zoukankan      html  css  js  c++  java
  • grep正则表达式(二)

    任意字符(The Any Character)

    dot or period character: "."

    grep -h '.zip' dirlist*.txt
    

    "."代表任意字符,但是zip不符合,因为"."必须代表一个字符。所以符合条件的字符串至少要含4个字符。

    bunzip2
    bzip2
    bzip2recover
    gunzip
    gzip
    funzip
    gpg-zip
    preunzip
    prezip
    prezip-bin
    unzip
    unzipsfx
    

    锚定字符(Anchors)

    beginning of the line "^"
    end of the line "$"

    grep -h '^zip' dirlist*.txt
    

    字符串必须以"zip"开头:

    zip
    zipcloak
    zipgrep
    zipinfo
    zipnote
    zipsplit
    
    grep -h 'zip$' dirlist*.txt
    

    字符串必须以"zip"结尾

    gunzip
    gzip
    funzip
    gpg-zip
    preunzip
    prezip
    unzip
    zip
    

    两个比较特殊的情况:

    grep -h '^zip$' dirlist*.txt
    

    只有字符串zip符合。

    grep -h '^$'  dirlist*.txt
    

    代表 blank lines 空白行

    方括号表达式[]

    grep -h '[bg]zip' dirlist*.txt
    

    查找包含bzipgzip的字符串。注意
    所有字符或元字符(metacharacter)放在方括号里都会失掉特殊含义,除了两个特例:^-。例如:

    否定(Negation)^

    grep -h '[^bg]zip' dirlist*.txt
    

    查找包含zip的字符串,但是_不能_是bzipgzip

    grep -h '^[A-Z]' dirlist*.txt
    

    查找以26个大字字母_开头_的字符串。-在这里是 range。

  • 相关阅读:
    c#声明数组
    【游戏物理】欧拉、龙格、韦尔莱
    当const放在function声明后
    【物理】AABB物理碰撞检测
    100 Path Sum
    Loop Unrolling 循环展开
    Unity Shader and Effects Cookbook问题记录
    【ShaderToy】画一个球体
    pymysql
    mysql表间的关系和查询
  • 原文地址:https://www.cnblogs.com/yaos/p/6940575.html
Copyright © 2011-2022 走看看