Use regex to search for NOT text between two characters

I have one line of words in which each word is separated by a newline. I used RegEx replacements to insert { and } ' characters around common prefixes and suffixes. The result is as follows:

{con}descens{ion}
lumberjack
tim{ing}
{tox}{icity}
fish
{dis}pel

What I'm trying to understand is how I can perform a RegEx replacement on this line that will only match text not between { and " } . I have additional replacements to do, and every time I do this, I I’ll put the characters { and } ; I just don’t want the previous replacements (or parts of them) to match when making new replacements. I know how to match “not” {"", for example, but I don’t know how to combine “not between "{'and'} '"

To take this into perspective, an example of the following replacement operation here is to replace all the characters " n " with the characters " 7 ". In this case, the first line of the string "{con} descens {ion}" should become "{con} desce {7} s {ion}", and not "{co {7}} desce {7} s {w {7} } "; other words will remain unchanged based on these criteria.

Any suggestions?

+4
source share
2 answers

Assuming your braces are always balanced, you can use a negative Lookahead here.

[a-zA-Z]+(?![^{]*\})

.. A to Z, , , .

[^}]+(?![^{]*\})

+9

, , :

(?<=^|\})[^{]+

, look-behind ( ), :

(^|})([^{])

: 1 }, , 2 . , , 1.

, .

+2

Source: https://habr.com/ru/post/1542606/


All Articles