Regular Expression

It's a very elegant summary of regular expression from The AWK Programming Language.

 

1. The regular expression metacharacters are:  

 \ ^ $ . [ ] | ( ) * + ?

 

2. A basic regular expression is one of the following:

  • a nonmetacharacter, such as A, that matches itself.
  • an escape sequence that matches a special symbol: \t matches a tab.
  • a quoted metacharacter, such as \*, that matches the metaqcharacter literally.
  • ^, which matches the beginning of a string.
  • $, which matches the end of a string.
  • ., which matches any single character.
  • a character class: [ABC] matches any of the characters A, B, or C. Character classes may include abbreviations: [A-Za-z] matches any single letter.
  • a complemented character class: [^0-9] matches any character except a digit.

 

3. These operators combine regular expressions into larger ones:

  • alternation: A | B matches A or B.
  • concatenation: AB matches A immediately followed by B.
  • closure: A* matches zero or more A's.
  • positive closure: A+ matches one or more A's.
  • zero or one: A? matches the null string or A.
  • parentheses: (r) matches the same strings as r does.

 


 

Regular Expressions
ExpressionMatches
c the nonmetacharacter c
\c escape sequence or literal character c
 ^ beginning of string 
 $ end of string
 . any character
 [$c_1$$c_2$...] any character in $c_1$$c_2$
 [^$c_1$$c_2$...] any character not in $c_1$$c_2$
[$c_1$-$c_2$]  any character in the range beginning with $c_1$ and ending with $c_2$
 [^$c_1$-$c_2$] any character not in the range $c_1$ to $c_2$
 $r_1$|$r_2$ any string matched by $r_1$ or $r_2$
($r_1$)($r_2$)  any string xy where $r_1$ matches x and $r_2$ matches y; parentheses not needed around arguments with no alternations
 (r)* zero or more consecutive strings matched by r 
 (r)+ one or more consecutive strings matched by r
 (r)? zero or one string matched by r parentheses not needed around basic regular expressions 
 (r) any string matched by r

转载于:https://www.cnblogs.com/kid551/p/4177854.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值