CMD List [7]

1          Regular Expressions 正则表达式

 

(1)      Pattern could be wildcard or regular expression; most of them are the same usage; but some are different.

(2)      Wildcard can be used in sed, awk, grep, egrep etc.; regular expression can be used in sed, awk, grep -E, egrep etc.

(3)      grep -E, egrep and awk use extend regular expressions, perl even more extended.

 

Option or argument

Function

(x)

Regular expression for grouping.

^

(1) 对行首

e.g.

^the对以the开头行

^d..x..x..x 对用户、用户组及其他用户组成员有可执行权限的目录

$

对行尾

e.g.

^USER$ 对只包含USER的行

[tty]$ 对表示以 t 或者 y 结尾的行

[^$] 对空行

[xy]  [a-c]

Any single character in the set specified.

e.g

[Ss]igna[lL]对匹配单词signalsignaLSignalSignaL

[Ss]igna[lL]\. 对同上,但加一句点

[mayMAY] 对包含mayMAY中任一字母的行

[iI] [nN] 对大写或小写in

[Dd]evice 对单词deviceDevice

[^xy]  [^a-c]

Any single character NOT in the set specified.

e.g.

[^0-9\$] 对非数字或美元标识

.

Any single character.

e.g.

^......$ 对包括6个字符的行

x*  [a-c]*

Zero or more occurrences of character x.

e.g.

[a-z][a-z]* 对至少一个小写字母

x+  expr+

One or more occurrences of character x or regular expression.

x?  expr?

Zero or one occurrences of character x or regular expression.

x|y

Either x or y.

\x

(1) Force to read as letter, not as meaning it has.

e.g.

\^q对以^q开始行

^\.[0-9][0-9] 对以一个句点和两个数字开始的行

 

(2) e.g.

[0-9]\{2\}-[0-9]\{2\}-[0-9]\{4\} 对日期格式dd-mm-yyyy

(order)

The operators order is [, ], *, ?, +, concatenation, |

 

Symbol

ed

ex

vi

sed

awk

grep

egrep

Action

.

Y

Y

Y

Y

Y

Y

Y

Match any character.

*

Y

Y

Y

Y

Y

Y

Y

Match zero or more preceding.

^

Y

Y

Y

Y

Y

Y

Y

Match beginning of line.

$

Y

Y

Y

Y

Y

Y

Y

Match end of line.

\

Y

Y

Y

Y

Y

Y

Y

Escape character following.

[ ]

Y

Y

Y

Y

Y

Y

Y

Match one from a set.

\(\)

Y

Y

 

Y

 

 

 

Store pattern for later replay.

\{\}

Y

 

 

Y

 

Y

 

Match a range of instances.

\<\>

Y

Y

Y

 

 

 

 

Match word's beginning or end.

+

 

 

 

 

Y

 

Y

Match one or more preceding.

?

 

 

 

 

Y

 

Y

Match zero or one preceding.

|

 

 

 

 

Y

 

Y

Separate choices to match.

()

 

 

 

 

Y

 

Y

Group expressions to match.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值