Groovy定期匹配引号之间的所有内容 [英] Groovy Regular matching everything between quotes
本文介绍了Groovy定期匹配引号之间的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个正则表达式
regex =〜/ \([^] *)\/
所以我寻找引号之间的所有文本
现在我有以下字符串
options ='a:2:{s:10:打印类型; s:8:新书; s:8: Template; s:9:See Notes;}'
无论如何
regex.matcher(options).matches()=> false
应该不是这样,我不应该有4个组
解决方案
< matcher()
方法会尝试将整个字符串与失败的正则表达式匹配。
请参阅本教程了解更多信息。
我不不知道Groovy,但它看起来像下面的应该工作:
pre $ def mymatch ='a:2:{s:10 :Print Type; s:8:New Book; s:8:Template; s:9:See Notes;}'= 〜/([^] *)/
现在 mymatch。每个{println it [1]}
应该打印所有匹配。
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
解决方案
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.
这篇关于Groovy定期匹配引号之间的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文