本文介绍了Groovy正则表达式/模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何在groovy中进行正则表达式匹配,下面的示例中groovy中的正则表达式将是什么?
How do we do regex matching in groovy, what will be the regex in groovy for below example?
Example : f2376 Regex: (anyLetter)(followed by 4 digits) 推荐答案使用Groovy非常简单
Pretty simple with groovy
"f1234" ==〜/[a-z] \ d {4}/
请注意,正则表达式 [az] \ d {4} 表示任何字符az一次,后跟正好4位数字,并且可以与任何处理正则表达式的语言一起使用,而不是只是很时髦.
Note that the regex [a-z]\d{4} means any of the characters a-z once, followed by exactly 4 digits, and can be probably be used with any language that handles regex, not just groovy.
在我的控制台中,我仅测试了小写字母,但也可以处理大写字母
In my console I tested for just lower case letters, but to handle upper case too just do
"f1234" ==〜/[a-zA-Z] \ d {4}/
更多推荐
Groovy正则表达式/模式匹配
发布评论