Search code examples
regexspecial-charactersnotepad++

Remove special characters between digits up to a limit using regex


How do I remove the special characters [ and ] below using regex, while preserving the square brackets at the back of the sentence?

From

468620188,[2012-07-07 00:00:00,057],[Thread-20],INFO,BIZ,Handler,getJobs,[Result] Retrieving broadcast []

To

468620188,2012-07-07 00:00:00,057,Thread-20,INFO,BIZ,Handler,getJobs,[Result] Retrieving broadcast []

Solution

  • This works with perl REs, using a lookahead:

    s/[\[\]](?=.*,)//g;
    

    It removes any [ or ] character that has a , character somewhere after it.

    If you're not using perl, this probably won't be as useful.


    EDIT:

    This might work:

    1. Search for \[([^\n]*,), replace with \1. Hit Replace All
    2. Search for \]([^\n]*,), replace with \1. Hit Replace All.

    Please note I don't have access to Notepad++ to test this; I'm just going off some screen shots of the search box I found online.