2005-10-22

揭开正则表达式语法的神秘面纱

来源: 本站收集整理 作者:佚名 评论 0 条
 

grep [a-zA-Z]ord sample.txt

Will match “aord”, “bord”, “Aord”, “Bord”, etc.

grep [^0-9]ord sample.txt

Will match “Aord”, “aord”, etc. but not “2ord”, etc.


重复操作符

重复操作符,或数量词,都描述了查找一个特定字符的次数。它们常被用于字符匹配语法以查找多行的字符,可参见表B。


(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:将SSH与PHP相连接 确保传输数据的安全  
下一篇:准备选举自己最喜欢的开发工具
    评论加载中…

Table B: Regular expression repetition operators

操作

解释

例子

结果

?

Match any character one time, if it exists

egrep “?erd” sample.txt

Will match “berd”, “herd”, etc. and “erd”

*

Match declared element multiple times, if it exists

egrep “n.*rd” sample.txt

Will match “nerd”, “nrd”, “neard”, etc.

Match declared element one or more times

egrep “[n] erd” sample.txt

Will match “nerd”, “nnerd”, etc., but not “erd”

{n}

Match declared element exactly n times

egrep “[a-z]{2}erd” sample.txt

Will match “cherd”, “blerd”, etc. but not “nerd”, “erd”, “buzzerd”, etc.

{n,}

Match declared element at least n times

egrep “.{2,}erd” sample.txt

Will match “cherd” and “buzzerd”, but not “nerd”

{n,N}

Match declared element at least n times, but not more than N times

共4页: 上一页 [1] 2 [3] [4] 下一页
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号