首页 > 系统服务 > 详细

linux正则表达式(一)

时间:2017-07-25 09:19:08      阅读:202      评论:0      收藏:0      [点我收藏+]

  正则表达式是一种字符串模式匹配,使用灵活、功能强大,使用简单的方式对字符串进行控制。

1.使用grep进行字符串匹配

测试文本 1.txt

helloworld
haa
12345678
!@#$%^&*(
ASDwexvRSD
,./]];]{}_()^%
asdasdasd

 搜索文件中包含"hello"

grep -n hello 1.txt

  利用中括号 [] 来搜寻集合字符

$ grep -n "h[ae]" 1.txt
1:helloworld
2:haa

行首与行尾字符 ^ $

$ grep -n "^he" 1.txt
1:helloworld
$ grep -n %$ 1.txt
6:,./]];]{}_()^%

任意一个字符 . 与重复字符 *

$ grep -n h. 1.txt
1:helloworld
2:haa
$ grep -n "he.*ld" 1.txt
1:helloworld

限定连续 RE 字符范围 {}

$ grep -n ha\{2\} 1.txt
2:haa

 

linux正则表达式(一)

原文:http://www.cnblogs.com/lzeffort/p/7231884.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!