加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

扩展正则表达式

发布时间:2020-12-13 22:57:10 所属栏目:百科 来源:网络整理
导读:1. 扩展正则表达式 扩展正则表达式 ERE Extended Regular Expressions 比基本正则表达式BRE 拥有更强大的功能。 2. ERE字符 egrep表示使用扩展正则表达式, 可以用 grep -E 代替 + 重复前面字符一次或多次 要匹配 god , good, goood 使用: grep -E 'go+d'

1. 扩展正则表达式


扩展正则表达式 ERE Extended Regular Expressions 比基本正则表达式BRE 拥有更强大的功能。

2. ERE字符


egrep表示使用扩展正则表达式,
可以用 grep -E 代替
+  重复前面字符一次或多次
   要匹配 god , good,  goood 使用:
   grep -E 'go+d' test
? 重复前面字符0次或一次
   匹配gd 或 god, 使用
   grep -E 'go?d' test
|  表示 或
   匹配good或bad,使用
   grep -E 'good|bad' test
() 分组
   要查找glad 或good, g和d相同,把la 和oo分组:
   grep -E 'g(la|oo)d' test
()+ 多个重复组的判断
   匹配 AabcabcabcC 中间abc为多组
   grep -E 'A(abc)+C' test 

3. 简写


简写的特殊字符
Character Class Abbreviations
d	Match any character in the range 0 - 9 (equivalent of POSIX [:digit:])
D	Match any character NOT in the range 0 - 9 (equivalent of POSIX [^[:digit:]])
s	Match any whitespace characters (space,tab etc.). (equivalent of POSIX [:space:] EXCEPT VT is not recognized)
S	Match any character NOT whitespace (space,tab). (equivalent of POSIX [^[:space:]])
w	Match any character in the range 0 - 9,A - Z and a - z (equivalent of POSIX [:alnum:])
W	Match any character NOT the range 0 - 9,A - Z and a - z (equivalent of POSIX [^[:alnum:]])
Positional Abbreviations
b	Word boundary. Match any character(s) at the beginning (bxx) and/or end (xxb) of a word,thus btonb will find ton but not tons,but bton will find tons.
B	Not word boundary. Match any character(s) NOT at the beginning(Bxx) and/or end (xxB) of a word,thus BtonB will find wantons but not tons,but tonB will find both wantons and tons.

地址: http://www.52php.cn/article/p-szhjxzwq-qn.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读