Regex matches words separated by '!' and enclosed between braces '{' '}'

I am trying to parse a string and get all the words enclosed between braces {} that have '!' in him. Input Example:
"This is {matchA} and {matchB} but I need {matchC!matchD}, however {matchE} doesn't count but {matchF!matchG} is what I'm looking for"

I used (?<=\{)(.*?)(?=\}) And {(?:\.|(\\{)|[^}'\n])*} to get all matches between {} , but as a match, it returns the following:
"matchA" , "matchB" , "matchC!matchD" , "matchE" and "matchF!matchG" as matches

However, I try to get only matches that have a "!" in them the result should be only: "matchC!matchD" and "matchF!matchG" and ignore the rest.

I am very grateful for the help. Thank you all for your answers.

+4
source share
1 answer

Insert an exclamation mark and use character classes instead of intransigence.

 {([^}]+![^}]+)} 
+4
source

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


All Articles