1

I want to match strings containing MYSTUFF in all cases, except when MYSTUFF is preceded by ENABLED_. So that the following would match:

  • MYSTUFF
  • m_MYSTUFF
  • MYSTUFFIsGreat
  • allOf_MYSTUFF

but the following wouldn't:

  • ENABLED_MYSTUFF
  • m_ENABLED_MYSTUFF
  • ENABLED_MYSTUFFIsGreat
  • allOf_ENABLED_MYSTUFF

I tried several variations using negative lookahead (variations of \w*(?!.*ENABLED_)MYSTUFF\w*), and conditional (variations of (?(?!=ENABLED_)(MYSTUFF))), but I did not manage to get the results I'm after.

Is what I want even doable with regexes?

joce
  • 9,624
  • 19
  • 56
  • 74

1 Answers1

2

You could accomplish this by using a negative look-behind assertion ...

\w*(?<!ENABLED_)MYSTUFF\w*

see regex demo

m87
  • 4,445
  • 3
  • 16
  • 31