zoukankan      html  css  js  c++  java
  • [正则]排除字符组

      在正则表达式模式中,你也可以反转自读组的作用,你可以寻找组中没有的任意字符,而不是去寻找组中含有的字符。要这么做的话,只要在字符组的开头加个脱字符:

    例如,data6的内容如下:

    This is a test line
    This is a different line.
    This is a test of line
    The cat is sleeping
    That is a very nice hat.
    at ten o'clock we'll go home
    This test is at line two
    hhi data6's content

    匹配开头不是T开头的的

    sed -n '/[^Ts]hi/p' data6

    这时,所有带有hi并且开始的字符串为T和s的都滤除了。

    输出:

    hhi data6's content

    注意,因为^也代表在首字母匹配,当把^符号移出[]内时,匹配的就是在开头是T和s开头并带有hi的字符了

    sed -n '/^[Ts]hi/p' data6

    输出:

    This is a test line
    This is a different line.
    This is a test of line
    This test is at line two
  • 相关阅读:
    类与对象
    《大道至简》第三章读后感
    动手动脑及课后作业
    课程作业一
    第三周学习进度条
    软件工程个人作业02
    第二周学习进度条
    软件工程个人作业01(2)
    软件工程个人作业01
    登录界面
  • 原文地址:https://www.cnblogs.com/jacson/p/4802047.html
Copyright © 2011-2022 走看看