简体   繁体   中英

Match all characters except one

I have a test string with pattern

{something1=any_character} any_character {something2=any_character}

I wanted to match the first bracketed sequence and in next iteration I wanted to match the next. So I am using Pattern and Matcher .

The regex I have is \\{(\\w)*something1.*(?!=).*(?!\\}) but the problem is that it match the complete string rather then just the first one. I want to break the first search at first } and then find next } .

只是使通配符变得懒惰:

\\{(\\w)*?something1.*?(?!=).*?\\}

If you are using Pattern and Matcher , then only capture groups like this :

(\\\\{\\\\w+=\\\\w+\\\\}) and use a while() loop with matcher.find()

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