这里就介绍得比较全了,有基本的,扩展的,POSIX的,GNU的,确实这本书不错。
一,基本的正则表达式

二,扩展正则表达式

三,POSIX规范的正则表达式

四,GNU规范的正则表达式

五,实践测试
1008 cp /etc/passwd /tmp/
1009 grep "root" /tmp/passwd
1010 grep ":..0:" /tmp/passwd
1011 grep "00*" /tmp/passwd
1012 grep "o[os]t" /tmp/password
1013 grep "o[os]t" /tmp/passwd
1014 grep "[0-9]" /tmp/passwd
1015 grep "[f-q]" /tmp/passwd
1016 grep "^root" /tmp/passwd
1017 grep "bash$" /tmp/passwd
1018 grep "sbin/[^n]" /tmp/passwd
1019 grep "0\{1,2\}" /tmp/passwd
1020 grep "\(root\).*\1" /tmp/passwd
1021 grep "^$" /tmp/passwd
1022 grep -v "^$" /tmp/passwd
1023 grep "0{1,2}" /tmp/passwd
1024 egrep "0{1,2}" /tmp/passwd
1025 grep -E "0{1,2}" /tmp/passwd
1026 grep "0+" /tmp/passwd
1027 egrep "0+" /tmp/passwd
1028 egrep "(root|admin)" /tmp/passwd
1029 grep "[[:digit:]]" /tmp/passwd
1030 grep "[[:alpha:]]" /tmp/passwd
1031 grep "[[:punct:]]" /tmp/passwd
1032 grep "[[:space:]]" /tmp/passwd
1033 grep "i\b" /tmp/passwd
1034 grep "\W" /tmp/passwd
1035 grep "\w" /tmp/passwd
1036 grep -P --color "\d" /etc/passwd
1037 grep -P --color "\D" /etc/passwd

网友评论