正则表达式全解析:基础、扩展与实战应用
1. 正则表达式基础
1.1 精确匹配数字
若要确保只匹配五个数字,需对其进行界定,可使用空格,或者像下面示例那样,表明它们位于行的开头和结尾:
$ sed -n '
> /^[0123456789][0123456789][0123456789][0123456789][0123456789]$/p
> ' data8
60633
46201
22203
$
1.2 处理拼写错误
字符类的一个常见用途是解析可能拼写错误的单词,例如用户表单输入的数据。可轻松创建能接受数据中常见拼写错误的正则表达式:
$ cat data9
I need to have some maintenence done on my car.
I'll pay that in a seperate invoice.
After I pay for the maintenance my car will be as good as new.
$ sed -n '
/maint[ea]n[ae]nce/p
/sep[ea]r[ea]te/p
' data9
I need to have some maintenence done on my car.
I'll pay that in a seperate invoice.
After I pay for the maintenance my car will be as good as new.
$
超级会员免费看
订阅专栏 解锁全文
37

被折叠的 条评论
为什么被折叠?



