美文网首页
扩展正则学习

扩展正则学习

作者: 蓝山_d851 | 来源:发表于2020-11-04 11:21 被阅读0次

仅供自己学习参考

扩展正则基础正则的加强版。

物料准备

[root@test001 tmp]# wget http://linux.vbird.org/linux_basic/0330regularex/regular_express.txt

删除空行和注释行#

[root@test001 tmp]# sed  's/^#//g' regular_express.txt  |  sed  '/^$/d'   
"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!

###扩展正则方式
[root@test001 tmp]# egrep  -v '^#|^$'  regular_express.txt 
"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!
更方便

特殊符号意义与范例
”+ “ 重复一个或者一个以上的前一个字符,如搜寻 good god goood 等字符串,那个o+ 代表一个以上的o (至少一个)

[root@test001 tmp]# egrep   -n 'go+g'   regular_express.txt 
18:google is the best tools for search keyword.
19:goooooogle yes!

"?" 零个或者1个前一个字符串 (最多一个)

[root@test001 tmp]# egrep  -n 'go?g'   regular_express.txt 

"|" 用or的方式找出多个条件的字符串

[root@test001 tmp]# egrep  -n  'gd|good|dog'  regular_express.txt 
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
14:The gd software is a library for drafting programs.
17:I like dog.

"()" 找出群组字符串

root@test001 tmp]# egrep  -n  'gd|good|dog'  regular_express.txt 
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
14:The gd software is a library for drafting programs.
17:I like dog.
[root@test001 tmp]# egrep   -n  'g(la|oo)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".

"()+"多个重复群组的判断

###找出 开头是A结尾是C中间是xyz的多个重复字符串
[root@test001 tmp]# echo  AxyzxyzxyzxyzxyzC   
AxyzxyzxyzxyzxyzC
[root@test001 tmp]# echo  AxyzxyzxyzxyzxyzC     |  egrep   'A(xyz)+C'
AxyzxyzxyzxyzxyzC

相关文章

  • 扩展正则学习

    仅供自己学习参考 扩展正则基础正则的加强版。 物料准备 删除空行和注释行# 特殊符号意义与范例”+ “ 重复一个...

  • Linux grep、egrep使用命令详解

    grep egrep区别grep 默认不支持扩展 但可以通过-E 选择来支持扩展正则egrep 支持扩展正则 ...

  • ES6扩展

    字符串的扩展正则的扩展数值的扩展数组的扩展函数的扩展对象的扩展

  • 三剑客_grep

    grep grep 相关参数 grep + 正则表达式(扩展正则)

  • linux正则表达式详解(二) -扩展正则表达式

    上一章我们主要探讨了通配符和基础正则表达式,这章重点探讨扩展正则表达式的应用。 基本正则表达式包含: 扩展正则添加...

  • JavaScript ES6 - 正则表达式扩展

    正则扩展: 主要来与 ES5 做一个对比 (也就是语法的扩展) 1. ES6 正则新特性: 如图所示: 1. 正则...

  • ES6学习 第五章 正则的扩展

    前言 本章介绍正则的扩展。有些不常用的知识了解即可。本章原文链接:正则的扩展[https://es6.ruanyi...

  • 正则扩展

    修饰符i:不区分大小写es5中,有两种写法:1.两个参数 2.一个参数 结果:i y修饰符## y和g的相同点:都...

  • 正则扩展

    正则新特性 构造函数的变化,正则方法的扩展,u修饰符,y修饰符,s修饰符 es5正则的写法 es6新增 y修饰符 ...

  • 正则扩展

    RegExp 构造函数 在 ES5 中,RegExp构造函数的参数有两种情况。 第一种情况是,参数是字符串,这时第...

网友评论

      本文标题:扩展正则学习

      本文链接:https://www.haomeiwen.com/subject/qczwvktx.html