开发者

Groovy Regular matching everything between quotes

开发者 https://www.devze.com 2023-02-06 15:38 出处:网络
I have this regex regex = ~/\\\"([^\"]*)\\\"/ so Im looking for all text between quotes now i have the follow开发者_开发百科ing string

I have this regex

regex = ~/\"([^"]*)\"/

so Im looking for all text between quotes now i have the follow开发者_开发百科ing string

options = 'a:2:{s:10:"Print Type";s:8:"New Book";s:8:"Template";s:9:"See Notes";}'

however doing

regex.matcher(options).matches() => false

should this not be true, and shouldn't I have 4 groups


The matcher() method tries to match the entire string with the regex which fails.

See this tutorial for more info.

I don't know Groovy, but it looks like the following should work:

def mymatch = 'a:2:{s:10:"Print Type";s:8:"New Book";s:8:"Template";s:9:"See Notes";}' =~ /"([^"]*)"/

Now mymatch.each { println it[1] } should print all the matches.

0

精彩评论

暂无评论...
验证码 换一张
取 消