20160804课堂作业

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

blob.png

# 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

blob.png

2、用正则表达式表示手机号11, 13, 17, 15, 18开头

# grep "^1[13578][[:digit:]]\{,9\}" fg 

blob.png

# grep -E -o "^\b1[3578][0-9]{9}\b" fg

blob.png

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

blob.png

4、  用正则表达式表示邮箱

# grep -E "\<([[:alnum:]]+(-|_)*[[:alnum:]]*)\>@([[:alnum:]]+\.)+[[:alnum:]]+" mail

blob.png

 

原创文章,作者:Aaron_wang,如若转载,请注明出处:http://www.178linux.com/29511