简体   繁体   中英

Regex to match words separated by '!' and enclosed between curly brackets '{' '}'

I'm trying to parse a string and get all the words enclosed between curly brackets {} that has '!' in it.
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 have used (?<=\\{)(.*?)(?=\\}) and {(?:\\.|(\\\\{)|[^}'\\n])*} to get all the matches between the {} but it returns the following as matches:
"matchA" , "matchB" , "matchC!matchD" , "matchE" and "matchF!matchG" as matches

However, I'm trying to get only the matches that has '!' in them, so the result should be only: "matchC!matchD" , and "matchF!matchG" and ignores the rest.

I would really appreciate the help. Thank you all in advance for your answers

将感叹号放在那里并使用字符类而不是非贪婪。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM