2005-10-22

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

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

egrep “n[e]{1,2}rd” sample.txt

Will match “nerd” and “neerd”

锚是指它所要匹配的格式,如图C所示。使用它能方便你查找通用字符的合并。例如,我用vi行编辑器命令:s来代表substitute,这一命令的基本语法是:

s/pattern_to_match/pattern_to_substitute/


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

Table C: Regular expression anchors

操作

解释

例子

结果

^

Match at the beginning of a line

s/^/blah /

Inserts “blah “ at the beginning of the line

$

Match at the end of a line

s/$/ blah/

Inserts “ blah” at the end of the line

\<

Match at the beginning of a word

s/\</blah/

Inserts “blah” at the beginning of the word

egrep “\<blah” sample.txt

Matches “blahfield”, etc.

\>

Match at the end of a word

s/\>/blah/

Inserts “blah” at the end of the word

egrep “\>blah” sample.txt

Matches “soupblah”, etc.

\b

Match at the beginning or end of a word

egrep “\bblah” sample.txt

Matches “blahcake” and “countblah”

\B

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

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