js 自定义 trim 函数的具体使用方法详解
712
2022-09-22
正则表达式练习
2013年3月8日 星期五 晴 有风
正则表达式练习
"Open Source" is a good mechanism to develop programs.
apple is my favorite food.
Football game is not use feet only.
this dress doesn't fit me.
However, this dress is about $ 3183 dollars.
GNU is free air not free beer.
Her hair is very beauty.
I can't finish the test.
Oh! The soup taste good.
motorcycle is cheap than car.
This window is clear.
the symbol '*' is represented as start.
Oh! My god!
The gd software is a library for drafting programs.
You are the best is mean you are the no. 1.
The world
I like dog.
google is the best tools for search keyword.
goooooogle yes!
go! go! Let's go.
# I am VBird
1、过滤-文件中包含 the 关键字
2、过滤-文件中丌包含 the 关键字
3、过滤-文件中丌论大小写 the 关键字
4、过滤 test 或 taste 这两个单字
5、过滤有 oo 的字节
6、过滤丌想要 oo 前面有 g 的
7、过滤 oo 前面丌想有小写字节
8、过滤有数字的那一行
9、过滤以 the 开头的
10、过滤以小写字母开头的
11、过滤开头丌是英文字母
12、过滤行尾结束为小数点.那一行
13、过滤空白行
14、过滤出 g??d 的字串
15、过滤至少两个 o 以上的字串
16、过滤 g 开头和 g 结尾但是两个 g 之间仅存在至少一个 o
17、过滤任意数字的行
18、过滤两个 o 的字串
19、过滤 g 后面接 2 到 5 个 o,然后在接一个 g 的字串
20、过滤 g 后面接 2 个以上 o 的
所给答案
[root@desktop1 ~]# grep -n 'the' regular_express.txt
[root@desktop1 ~]# grep -vn 'the' regular_express.txt
[root@desktop1 ~]# grep -in 'the' regular_express.txt
[root@desktop1 ~]# grep -n 't[ae]st' regular_express.txt
[root@desktop1 ~]# grep -n 'oo' regular_express.txt
[root@desktop1 ~]# grep -n '[^g]oo' regular_express.txt
[root@desktop1 ~]# grep -n '[^a-z]oo' regular_express.txt
[root@desktop1 ~]# grep -n '[^[:lower:]]oo' regular_express.txt
[root@desktop1 ~]# grep -n '[0-9]' regular_express.txt
[root@desktop1 ~]# grep -n '[[:digit:]]' regular_express.txt
[root@desktop1 ~]# grep -n '^the' regular_express.txt
[root@desktop1 ~]# grep -n '^[a-z]' regular_express.txt
[root@desktop1 ~]# grep -n '^[[:lower:]]' regular_express.txt
[root@desktop1 ~]# grep -n '^[^a-zA-Z]' regular_express.txt
[root@desktop1 ~]# grep -n '^[^[:alpha:]]' regular_express.txt
[root@desktop1 ~]# grep -n '\.$' regular_express.txt
[root@desktop1 ~]# grep -n '^$' regular_express.txt
[root@desktop1 ~]# grep -n 'g..d' regular_express.txt
[root@desktop1 ~]# grep -n 'ooo*' regular_express.txt
[root@desktop1 ~]# grep -n 'goo*g' regular_express.txt
[root@desktop1 ~]# grep -n 'goo*g' regular_express.txt
[root@desktop1 ~]# grep -n '[0-9][0-9]*' regular_express.txt
[root@desktop1 ~]# grep -n 'o\{2\}' regular_express.txt
[root@desktop1 ~]# grep -n 'go\{2,5\}g' regular_express.txt
[root@desktop1 ~]# grep -n 'go\{2,\}g' regular_express.txt
练习情况
1、过滤-文件中包含 the 关键字
[root@desktop7 Desktop]# grep -n "the" regular_express.txt --color
8:I can't finish the test.
12:the symbol '*' is represented as start.
15:You are the best is mean you are the no. 1.
16:The world
18:google is the best tools for search keyword.
[root@desktop7 Desktop]#
2、过滤-文件中不包含 the 关键字
[root@desktop7 Desktop]# grep -vn "the" regular_express.txt --color
1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:Football game is not use feet only.
4:this dress doesn't fit me.
5:However, this dress is about $ 3183 dollars.
6:GNU is free air not free beer.
7:Her hair is very beauty.
9:Oh! The soup taste good.
10:motorcycle is cheap than car.
11:This window is clear.
13:Oh! My god!
14:The gd software is a library for drafting programs.
17:I like dog.
19:goooooogle yes!
20:go! go! Let's go.
21:# I am VBird
22:
[root@desktop7 Desktop]#
3、过滤-文件中不论大小写 the 关键字
[root@desktop7 Desktop]# grep -in "the" regular_express.txt --color
8:I can't finish the test.
9:Oh! The soup taste good.
12:the symbol '*' is represented as start.
14:The gd software is a library for drafting programs.
15:You are the best is mean you are the no. 1.
16:The world
18:google is the best tools for search keyword.
[root@desktop7 Desktop]#
4、过滤 test 或 taste 这两个单字
[root@desktop7 Desktop]# grep -n "t[ea]st" regular_express.txt --color
8:I can't finish the test.
9:Oh! The soup taste good.
[root@desktop7 Desktop]#
5、过滤有 oo 的字节
[root@desktop7 Desktop]# grep -n "ooo*" regular_express.txt --color
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!
[root@desktop7 Desktop]#
6、过滤不想要 oo 前面有 g 的
[root@desktop7 Desktop]# grep -n '[^g]oo' regular_express.txt --color
2:apple is my favorite food.
3:Football game is not use feet only.
18:google is the best tools for search keyword.
19:goooooogle yes!
[root@desktop7 Desktop]#
7、过滤 oo 前面不想有小写字节
[root@desktop7 Desktop]# grep -n '[^[:lower:]]oo' regular_express.txt --color
3:Football game is not use feet only.
过滤 oo 前面不想有数字
[root@desktop7 Desktop]# grep -n '[^[:digit:]]oo' regular_express.txt --color
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!
[root@desktop7 Desktop]#
8、过滤有数字的那一行
[root@desktop7 Desktop]# grep -n "[[:digit:]]" regular_express.txt --color
5:However, this dress is about $ 3183 dollars.
15:You are the best is mean you are the no. 1.
[root@desktop7 Desktop]#
9、过滤以 the 开头的
[root@desktop7 Desktop]# grep -n "^the" regular_express.txt --color 12:the symbol '*' is represented as start.
[root@desktop7 Desktop]#
10、过滤以小写字母开头的
[root@desktop7 Desktop]# grep -n "^[[:lower:]]" regular_express.txt --color
2:apple is my favorite food.
4:this dress doesn't fit me.
10:motorcycle is cheap than car.
12:the symbol '*' is represented as start.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.
[root@desktop7 Desktop]#
11、过滤开头不是英文字母
[root@desktop7 Desktop]# grep -vn "^[[:alpha:]]" regular_express.txt --color
1:"Open Source" is a good mechanism to develop programs.
21:# I am VBird
22:
检验:反向查找
[root@desktop7 Desktop]# grep -n "^[[:alpha:]]" regular_express.txt --color
2:apple is my favorite food.
3:Football game is not use feet only.
4:this dress doesn't fit me.
5:However, this dress is about $ 3183 dollars.
6:GNU is free air not free beer.
7:Her hair is very beauty.
8:I can't finish the test.
9:Oh! The soup taste good.
10:motorcycle is cheap than car.
11:This window is clear.
12:the symbol '*' is represented as start.
13:Oh! My god!
14:The gd software is a library for drafting programs.
15:You are the best is mean you are the no. 1.
16:The world
17:I like dog.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.
[root@desktop7 Desktop]#
12、过滤行尾结束为小数点.那一行
[root@desktop7 Desktop]# dos2unix regular_express.txt
dos2unix: converting file regular_express.txt to UNIX format ...
[root@desktop7 Desktop]# grep -n '\.$' regular_express.txt --color 1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:Football game is not use feet only.
4:this dress doesn't fit me.
5:However, this dress is about $ 3183 dollars.
6:GNU is free air not free beer.
7:Her hair is very beauty.
8:I can't finish the test.
9:Oh! The soup taste good.
10:motorcycle is cheap than car.
11:This window is clear.
12:the symbol '*' is represented as start.
14:The gd software is a library for drafting programs.
15:You are the best is mean you are the no. 1.
16:The world
17:I like dog.
18:google is the best tools for search keyword.
20:go! go! Let's go.
[root@desktop7 Desktop]#
13、过滤空白行
[root@desktop7 Desktop]# dos2unix regular_express.txt
dos2unix: converting file regular_express.txt to UNIX format ...
[root@desktop7 Desktop]# grep -n '^$' regular_express.txt --color
22:
[root@desktop7 Desktop]#
14、过滤出 g??d 的字串
[root@desktop7 Desktop]# grep -n 'g??d' regular_express.txt --color
无
[root@desktop7 Desktop]# grep -n 'g..d' regular_express.txt --color
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
16:The world
[root@desktop7 Desktop]#
15、过滤至少两个 o 以上的字串
第一种方式
[root@desktop7 Desktop]# grep -n 'ooo*' regular_express.txt --color
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!
[root@desktop7 Desktop]#
第二种方式
[root@desktop7 Desktop]# grep -n 'o\{2,\}' regular_express.txt --color
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!
[root@desktop7 Desktop]#
16、过滤 g 开头和 g 结尾但是两个 g 之间仅存在至少一个 o
[root@desktop7 Desktop]# grep -n 'goo*g' regular_express.txt --color
18:google is the best tools for search keyword.
19:goooooogle yes!
[root@desktop7 Desktop]#
17、过滤任意数字的行
[root@desktop7 Desktop]# grep -n '[[:digit:]]' regular_express.txt --color
5:However, this dress is about $ 3183 dollars.
15:You are the best is mean you are the no. 1.
[root@desktop7 Desktop]#
18、过滤两个 o 的字串
方法一:
[root@desktop7 Desktop]# grep -n 'oo' regular_express.txt --color
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!
[root@desktop7 Desktop]#
方法二:
[root@desktop7 Desktop]# grep -n 'o\{2\}' regular_express.txt --color
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!
[root@desktop7 Desktop]#
19、过滤 g 后面接 2 到 5 个 o,然后再接一个 g 的字串
[root@desktop7 Desktop]# grep -n 'go\{2,5\}g' regular_express.txt --color
18:google is the best tools for search keyword.
[root@desktop7 Desktop]#
20、过滤 g 后面接 2 个以上 o 的
方法一:
[root@desktop7 Desktop]# grep -n 'go\{2,\}' regular_express.txt --color
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
方法二:
[root@desktop7 Desktop]# grep -n 'gooo*' regular_express.txt --color
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
[root@desktop7 Desktop]#
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~