Groovy正则表达式

Regular expressions are the Swiss Army knife of text processing. They provide the programmer the ability to match and extract patterns from strings. The simplest example of a regular expression is a string of letters and numbers. And the simplest expression involving a regular expression uses the ==~ operator. So for example to match Dan Quayle's spelling of 'potato':




 



Regular Expression Operators
a? matches 0 or 1 occurrence of *a* 'a' or empty string
a* matches 0 or more occurrences of *a* empty string or 'a', 'aa', 'aaa', etc
a+ matches 1 or more occurrences of *a* 'a', 'aa', 'aaa', etc
a|b match *a* or *b* 'a' or 'b' -
. match any single character 'a', 'q', 'l', '_', '+', etc
[woeirjsd] match any of the named characters 'w', 'o', 'e', 'i', 'r', 'j', 's', 'd'
[1-9] match any of the characters in the range '1', '2', '3', '4', '5', '6', '7', '8', '9'
[^13579] match any characters not named even digits, or any other character
(ie) group an expression (for use with other operators) 'ie'
^a match an *a* at the beginning of a line 'a'
a$ match an *a* at the end of a line 'a'
There are a couple of other things you should know. If you want to use one of the operators above to
 mean the actual character, like you want to match a question mark, you need to put a '/' in front of it.
For example:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值