Search code examples
regexnotepad++

How to replace whitespace with notepad++ between two characters


I have question how to replace whitespace with _ using notepad++ regex between [] characters

Example :

sl.[Posting date]                       AS TIME, 
'0000-00-00'                            AS edate, 
sl.[Document No_], 
[Original Currency Factor]

Result

sl.[Posting_date]                       AS TIME, 
'0000-00-00'                            AS edate, 
sl.[Document_No_], 
[Original_Currency_Factor]

Solution

  • Find what: [.+(\s)+.+]

    Replace with: _

    Also don't forget to select Regular expression radio button in Search mode section.

    Update:

    Ok, I have one solution but it's dirty:

    You need to perform several replacements to do that.

    Find what: (\[.*)\s(.*\])

    Replace with: \1_\2

    Repeat using Replace all until there will be no occurrences.