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'
  • 相关阅读:
    网站建设怎样添加设为首页和加入收藏代码
    在WEB项目中调用QQ通讯组件打开QQ聊天界面
    网页引用Font Awesome图标
    jQuery鼠标划入划出
    django框架
    python连接数据库:
    数据库:
    TCP:
    数据库:
    Excel在任务栏中只显示一个窗口的解决办法
  • 原文地址:https://www.cnblogs.com/python-cat/p/12167880.html
Copyright © 2011-2022 走看看