Search code examples
regexnotepad++

How can i find specific charater in strings between two word?


I'm having trouble coming up with the regex I need to do this find/replace in Notepad++. I would like to find/replace specific character in strings between two words

for example

msgid "flower"
"test hold"
msgstr

I would like to find multiple o character between msgid " and msgstr and replace with a character. The result is

msgid "flawer"
"test hald"
msgstr

Solution

  • This looks very convoluted but should work for all cases:

    ((?:^.*?msgid "|\G)(?:(?!msgstr)[\s\S])*?)o(?=(?:(?!msgid ")[\s\S])*?msgstr)
    

    Replace with

    $1a
    

    See test cases here

    Basically what it does is to match os after seeing msgid ", after that get the end of previous match using \G and continue matching the rest of os before encountering msgstr.