zoukankan      html  css  js  c++  java
  • shell脚本--正则练习

    1.不打印空行和注释行

    grep -v -E '^#|^$' elasticsearch.yml 

     2.正则的特殊字符

    ?:  "?"前面的字符只允许出现一次或者零次

    [root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}@?qq.com'
    aaa@qq.com
    [root@manager1 shell]# echo "aaaqq.com"|grep -E 'a{3}@?qq.com'
    aaaqq.com
    [root@manager1 shell]#

    +: "+"前面的字符至少出现一次或者多次

    [root@manager1 shell]# echo "aaaqq.com"|grep -E 'a{3}@+qq.com'
    [root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}@+qq.com'
    aaa@qq.com

    *: "*"前面的字符可以出现0次或者多次

    [root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}@*qq.com'
    aaa@qq.com
    [root@manager1 shell]# echo "aaaqq.com"|grep -E 'a{3}@*qq.com'
    aaaqq.com

    | (管道符|):"|"类似于逻辑或or,可以用来过滤多个数据块

    [root@manager1 shell]# echo "aaa#qq.com"|grep -E 'a{3}[@|#]qq.com'
    aaa#qq.com
    [root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}[@|#]qq.com'
    aaa@qq.com

    ()组合代码块: "()"可以将多个字符组合成一个代码块

    [root@manager1 shell]# echo "aaaa@qq.com"|grep -E '^(aa){2}[@|#]qq.com'
    aaaa@qq.com

    {}:"{}"可以指定字符串或者代码块重复几次或者几到几次,使用','来指定范围

    [root@manager1 shell]# echo "aa@qq.com"|grep -E '^(aa){1,2}[@|#]qq.com'
    aa@qq.com
    [root@manager1 shell]# echo "aaaa@qq.com"|grep -E '^(aa){1,2}[@|#]qq.com'
    aaaa@qq.com
    [root@manager1 shell]# echo "aaaaaa@qq.com"|grep -E '^(aa){1,2}[@|#]qq.com'
  • 相关阅读:
    前端(基础篇)
    面向对象
    python(进阶篇)
    Python(基础篇)
    pycharm中添加python3 的环境变量
    MySQL与MongoDB的不同
    pycharm中添加python3 的环境变量
    ContentType&CORS&Git
    RESTful 组件
    Django REST_framework Quickstart
  • 原文地址:https://www.cnblogs.com/python-cat/p/12167880.html
Copyright © 2011-2022 走看看