zoukankan      html  css  js  c++  java
  • linux系统中正则表达式记录

    1、[^xx] 表示取反

    root@PC1:/home/test# ls
    a.txt
    root@PC1:/home/test# cat a.txt  ## 测试数据
    333
    d g 8 3
    d g !
    _ d g
    ! ! !
    , . ?
    root@PC1:/home/test# grep -v "3" a.txt   ## 只要匹配到3就排除
    d g !
    _ d g
    ! ! !
    , . ?
    root@PC1:/home/test# grep "[^3]" a.txt    ## 只有全部为3才排除
    d g 8 3
    d g !
    _ d g
    ! ! !
    , . ?
    root@PC1:/home/test# ls
    a.txt
    root@PC1:/home/test# cat a.txt
    333
    d g 8 3
    d g !
    555
    _ d g
    ! ! !
    , . ?
    root@PC1:/home/test# grep "[^3]" a.txt
    d g 8 3
    d g !
    555
    _ d g
    ! ! !
    , . ?
    root@PC1:/home/test# grep "[^35]" a.txt   ## 这里3和5是或的关系
    d g 8 3
    d g !
    _ d g
    ! ! !
    , . ?

    2、-w 表示匹配字符数字

    root@PC1:/home/test# ls
    a.txt
    root@PC1:/home/test# cat a.txt
    333
    d g 8 3
    d g !
    555
    _ d g
    ! ! !
    , . ?
    root@PC1:/home/test# grep "\w" a.txt    ## 匹配字符数字及下划线
    333
    d g 8 3
    d g !
    555
    _ d g

    -W表示匹配非字符数字:

    root@PC1:/home/test# ls
    a.txt
    root@PC1:/home/test# cat a.txt
    333
    d g 8 3
    d g !
    555
    _ d g
    !!!
    ,.?
    root@PC1:/home/test# grep "\W" a.txt   ## 匹配非字符数字及下划线
    d g 8 3
    d g !
    _ d g
    !!!
    ,.?

    3、

  • 相关阅读:
    Go 学习之旅
    IdentityServer4 3.1.x 迁移到 4.x
    Redash 二开
    frp 内网穿透远程桌面(Windows 10)配置
    Redash 二开
    Redash 二开
    Nginx 强制 HTTPS 配置
    ASP.NET Core 奇淫技巧之SPA部署
    .NET Core 对接微信小程序数据解密
    19c生产enq: FB
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15584037.html
Copyright © 2011-2022 走看看