Search code examples
regexnotepad++

notepad++ regex find and replace spaces between brackets


In notepad++, want to change this:

    [City tier] [nvarchar](max) NULL,
    [Counting unit] [nvarchar](max) NULL,

to this:

    [City_tier] [nvarchar](max) NULL,
    [Counting_unit] [nvarchar](max) NULL,

I have used [\w+(\s)\w+] to locate these two records, but when i use \1_ in replace, i got

     _ [nvarchar](max) NULL,
     _ [nvarchar](max) NULL,

Solution

  • You may use this PCRE regex for search:

    ((?:\[|(?!^)\G)[^]\s]*)\s
    

    and replace with:

    $1_
    

    RegEx Demo

    RegEx Details:

    • (: Start capture group #1
      • (?:: Start non-capture group
        • \[: Match a [
        • |: OR
        • (?!^)\G: Start matching again from end of the previous match
      • ): End non-capture group
      • [^]\s]*: Match 0 or more any characters that are not whitespace and not a ]
    • ): End capture group #1
    • \s: Match a whitespace