grep正则表达式课堂作业
1、用正则表达式表示IP地址
#grep -E "(\<[1-9]|[1-9][[:digit:]]|1[[:digit:]][[:digit:]]|2[0-4][[:digit:]]|25[0-5]\>)\.(\<[[:digit:]]|[1-9][[:digit:]]|1[[:digit:]]
[[:digit:]]|2[0-4][[:digit:]]|25[0-5]\>)\.(\<[[:digit:]]|[1-9][[:digit:]]|1[[:digit:]][[:digit:]]|2[0-4][[:digit:]]|25[0-5]\>)\.(\<[[:digit:]]|[1-9][[:digit:]]|1[[:digit:]][[:digit:]]|2[0-4][[:digit:]]|25[0-5]\>)" ip
# grep -E -o "(\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" ip
2、用正则表达式表示手机号11, 13, 17, 15, 18开头
# grep "^1[13578][[:digit:]]\{,9\}" fg
# grep -E -o "^\b1[3578][0-9]{9}\b" fg
3、 用正则表达式表示身份证号18位
# grep -E "\<((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|(71|81|82))([0-9]){4}(19|20)([0-9]){2}((0[1-9])|1([0-2]))(0[1-9]|([0-9])|(2[0-9])|(3[0-1]))([0-9]){3}([0-9]|X)\>" name
4、 用正则表达式表示邮箱
# grep -E "\<([[:alnum:]]+(-|_)*[[:alnum:]]*)\>@([[:alnum:]]+\.)+[[:alnum:]]+" mail
原创文章,作者:Aaron_wang,如若转载,请注明出处:http://www.178linux.com/29511