简体   繁体   中英

Regex: Match all characters between { and } if a specific string is between them

I have a string like this:

{name|val1|test}{name|val1|test}

And what I need is a RegEx which selects

{name|val1|test}

for example. Is that possible? I'm playing with Online RegExr for a while now but it seems that i'm to dumb to understand the syntax ;-) Currently I'm able to seperate the {...} groups:

\{.+?\}

The "syntax" of this strings is fix. It's not possible that there are brackets inside brackets.

The language is C#

Edited for clearance:

I want to select only one of the strings, depending on the value in the middle. For example, if im looking for "ID1" i only want to select the brackets and whats between them when they are containing "ID1".

在此处输入图片说明

只需将id放在正则表达式中,即可与之匹配:

/\{[^}]*ID1[^}]*\}/

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