0

With the expression below, I can find all the data that contains ToolTipML within the curly brackets. But what I am trying to do is selecting all the data that doesn't contain ToolTipML. Can anyone please point out what I am missing?

({[^{}]*?)(ToolTipML)([^}]*})

here is an example https://regex101.com/r/bNq6kV/1

  • Possible duplicate of [Regular expression to match a line that doesn't contain a word?](https://stackoverflow.com/questions/406230/regular-expression-to-match-a-line-that-doesnt-contain-a-word) – Ulysse BN Apr 01 '19 at 14:23

2 Answers2

0

I I understood you correctly, then you might use a negative lookahead:

{((?!ToolTipML)[^{}])*}

https://regex101.com/r/bNq6kV/3

Arfeo
  • 822
  • 6
  • 19
-1

Sadly, regex has no pattern negation, however a popular hack is to use repeated pattern of any-match, lookahead and then any-match.

For example, in your case the regex is (?s)\{(?:.(?!ToolTipML).)+?\}

We ensure that every character of input is not preceeded nor followed by the banned pattern. The drawback is that most regex implementations do not support variable-length lookahead/lookbehind patterns, but in your case it works flawlessly.

This is a popular question and it was already answered with more detail and explanations

necauqua
  • 74
  • 7