Regex how to match a substring that does not contain a fixed string. Regex in TexStudio:

StackOverflow https://stackoverflow.com/questions/22965003

  •  30-06-2023
  •  | 
  •  

Question

I want to a regex expression to replace the following string

{match1}{matchb}{not}{anotb}

with

match1matchb{not}{anotb}}

How to write the regex expression.

Basically I want to find a string inside {} but the string can not contain not.

Était-ce utile?

La solution

Search for the regex \{(?![^}]*not)([^}]+)\}

And replace with $1 or \1 based on your regex engine(or the function).

In the regex (?![^}]*not) is a negative lookahead that is checking that there is no not inside the {}.

Try it at regex101.

Autres conseils

You can match this:

\{([^}]*)\}\{([^}]*)\}\{not\}

and replace with:

\1\2{not}

Demo: http://regex101.com/r/uA8rU9

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top