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
  •  | 
  •  

質問

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.

役に立ちましたか?

解決

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.

他のヒント

You can match this:

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

and replace with:

\1\2{not}

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top