Search code examples
regexreplacefindnotepad++

Notepad++ RegEX how do I append a character based on start of the character and before a character?


I would like to append _OLD to the end of each strings that starts with SR_ but before the symbol ' or without it

For example my text is the following:

SR_Apple
When the 'SR_APPLE' rotten, we must discard it.

I would like the find and replace to do:

SR_Apple_OLD
When the 'SR_APPLE_OLD' rotten, we must discard it.

I have tried (SR_*)+$.*(?='\s) based on what i Learned but no luck so far. Please help. Thx in Adv


Solution

  • For simple cases you should be able to use

    Find: (\bSR_[\w]+)

    Replace: $1_OLD

    (\bSR_.+?)('|$) and $1_OLD$2 could also work if the text after SR_ is more complex

    The lookbehind you're using is only matching the string if it ends with a ' so it won't find the text not in quotes.

    regex101 is a useful tool for debugging expressions