Search code examples
regexregex-lookarounds

regex lookahead but ignore if specific char is found


so I have this text

onmousedown=
on mousedown=

I want to identify all "on" words that are succeded by a "=", but not if there is a space between the "on" word and the "=" => line 1 should be a match (on) => line 2 should not be a match


Solution

  • This should work for you:

    ^on[^ ]+=$
    

    it matches on followed by non-whitespace characters followed by =