Search code examples
regexsublimetext2textpad

Regex match a non-unique character in same string


Here is an example string. I have many more of these that I need to fix:

"måde", "answer" => "råd");

In this string there are 2 instances of the character å. I want find a match for the å in råd using regex, while ignoring the the å in måde.

So basically I need to find a match of an occurrence of å after answer.

I thought that (?<=answer)å(?=\;) would work, but I'm really new to this and would very much appreciate it if someone could point me in the right direction.

I tried asking this question before but got downvoted for some reason, so I tried to reformulate it here. I hope it is clear enough.


Solution

  • Look behinds (typically) can't be of variable length, but by using a negative look ahead, you tell it what not to match:

     å(?!.*answer)
    

    This matches "å", but only if "answer" doesn't appear somewhere after it.