正则表达式
来源:互联网 发布:ubuntu命令行修改文件 编辑:程序博客网 时间:2024/06/03 02:27
1.行首与行尾字符^$
行首:
oyzhx@ubuntu:~$ grep -n '^the' regular_express.txt 12:the symbol '*' is represented as start.行尾
oyzhx@ubuntu:~$ grep -n '\.$' regular_express.txt 1:"Open Source" is a good mechanism to develop programs.
2.任意个字符.与重复字符*
*:重复前一个字符的0-无穷个的意思.//a*
oyzhx@ubuntu:~$ grep -n 'ooo*' regular_express.txt 1:"Open Source" is a good mechanism to develop programs.2:apple is my favorite food.3:Football game is not use feet only.9:Oh! The soup taste good.18:google is the best tools for search keyword.19:goooooogle yes!.:代表一定有一个任意字符的意思.
oyzhx@ubuntu:~$ grep -n 'g..d' regular_express.txt 1:"Open Source" is a good mechanism to develop programs.9:Oh! The soup taste good.16:The world <Happy> is the same with "glad".".*"代表零个或多个任意字符
oyzhx@ubuntu:~$ grep -n 'g.*g' regular_express.txt 1:"Open Source" is a good mechanism to develop programs.14:The gd software is a library for drafting programs.18:google is the best tools for search keyword.19:goooooogle yes!20:go! go! Let's go.
3.限定连续RE字符范围{}
{2}表示2个,{2,}2个以上,{2,5}2个到5个
oyzhx@ubuntu:~$ grep -n 'go\{2,5\}g' regular_express.txt 18:google is the best tools for search keyword.4.sed工具
sed [-nefr]
-n:显示n特殊处理的那行
-e:命令行模式上进行sed的动作编辑
-f:将sed的动作写在一个文件内
-r:扩展型正则表达式的语法(默认是基础正则表达式语法)
-i:直接修改读取的文件内容,而不是由屏幕输出
[n1,[n2]] function
function 的参数
a,新增;c替换 d删除,i插入;p打印,s替换
5.扩展正则表达式
+:重复一个或一个以上的前一个RE字符. egrep -n 'go+d' aa.txt;
?:零个或一个的前一个RE字符 egrep -n 'go?d' aa.txt;
|:用或(or)的方式找出数个字符串 egrep -n 'gdlggod' aa.txt;
():找出“组字符串” egrep -n 'g(laloo)d' aa.txt;
()+:多个重复组的判别 echo 'AxyzxyzxuzusC'|egrep 'A(xyz) +C';
0 0
- 【正则表达式】正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- SVM中的数学和算法
- 一个逗比 程序员 web前端的理想!
- How to build a nice Hamburger Button transition in Swift(做动画可以参考下)
- 怎样完整的转换PDF格式文件
- Java 7 并发编程指南中文版
- 正则表达式
- log4j FileWatchdog工具类,用来监控文件,如有变动就执行特定的操作
- 自定义Adapter中getView( )中使用View.setTag()和不使用的区别。
- mint sogou
- ctags常用命令 -- linux
- 【No11.】仿IOS界面最常用的回弹效果
- mtk android代码如何修改mbr地址
- Symmetric Tree ,bfs
- 程序员如何写出杀手级的简历