Groovy Regular matching everything between quotes

 ̄綄美尐妖づ 提交于 2019-12-02 04:49:27

问题


I have this regex

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

so Im looking for all text between quotes now i have the following 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


回答1:


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.



来源:https://stackoverflow.com/questions/4803612/groovy-regular-matching-everything-between-quotes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!