正则表达式中的元字符* . ? +
*:匹配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}'
阅读(716) | 评论(1) | 转发(0) |