egrep “n[e]{1,2}rd” sample.txt
Will match “nerd” and “neerd”
锚是指它所要匹配的格式,如图C所示。使用它能方便你查找通用字符的合并。例如,我用vi行编辑器命令:s来代表substitute,这一命令的基本语法是:
s/pattern_to_match/pattern_to_substitute/
|
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] 下一页 | |||
![]() |