Chinaunix首页 | 论坛 | 博客
  • 博客访问: 927814
  • 博文数量: 146
  • 博客积分: 3321
  • 博客等级: 中校
  • 技术积分: 1523
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-29 10:32
文章分类

全部博文(146)

文章存档

2014年(2)

2013年(5)

2012年(4)

2011年(6)

2010年(30)

2009年(75)

2008年(24)

分类:

2009-07-25 10:10:38

正则表达式中的元字符* . ? +

*:匹配0个或多个前导字符
. :匹配除换行符外的所有单个字符.要想匹配 "."号时就要用转义字符\或者用[.]去匹配
? :匹配0个或一个前导字符。
+:匹配一个或多个前导字符。

例如:
1》
along@along-laptop:~/code/shell/shell$ echo "asd" | awk '$0~/e*/{print $0}'
asd
along@along-laptop:~/code/shell/shell$ echo "aed" | awk '$0~/e*/{print $0}'
aed

2》
along@along-laptop:~/code/shell/shell$ echo "aed" | awk '$0~/.*/{print $0}'
aed
along@along-laptop:~/code/shell/shell$ echo "a" | awk '$0~/\./{print $0}'
along@along-laptop:~/code/shell/shell$ echo "a" | awk '$0~/[.]/{print $0}'
along@along-laptop:~/code/shell/shell$ echo "a." | awk '$0~/[.]/{print $0}'
a.

3》
along@along-laptop:~/code/shell/shell$ echo "aa" | awk '$0~/a?/{print $0}'
aa
along@along-laptop:~/code/shell/shell$ echo "bb" | awk '$0~/a?/{print $0}'
bb

4》
along@along-laptop:~/code/shell/shell$ echo "bb" | awk '$0~/a+/{print $0}'
along@along-laptop:~/code/shell/shell$ echo "ab" | awk '$0~/a+/{print $0}'
ab
along@along-laptop:~/code/shell/shell$ echo "ba" | awk '$0~/a+[a-z]/{print $0}'



阅读(675) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-08-02 16:47:37

我怎么看不懂?? 小歪