• 请不要在回答技术问题时复制粘贴 AI 生成的内容
lcj2class
V2EX  ›  程序员

gnu linux 下各种文本处理命令(像 sed、awk 等)所使用的正则表达式,你知道区别吗?

  •  
  •   lcj2class · Dec 7, 2014 · 3261 views
    This topic created in 4179 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Oct 12, 2018
    5 replies    2014-12-08 12:27:22 +08:00
    ayang23
        1
    ayang23  
       Dec 7, 2014
    总结一下不错,BRE和ERE的区别经常让人头疼
    kidlj
        2
    kidlj  
       Dec 7, 2014
    GNU Grep 中的 BRE 和 GRE 没有功能性上的差别,不过一些符号的使用需要注意(man grep):

    如果使用的是 BRE,那么 ?, +, {, |, (, ) 将失去其特殊意义,这些功能应该使用 \?, \+, \{, \|, \(, \)来替代。

    =====

    我也刚总结了一下BRE 和 GRE,然后通过实验来获知具体哪个工具程序使用的是 BRE,ERE还是PCRE。

    http://kidlj.com/wiki/regex.html
    lsmgeb89
        3
    lsmgeb89  
       Dec 7, 2014
    awk, sed 最头疼了,加上各种 re 的区别,转义字符,单引号,双引号。每次写个 shell 都要折腾半天。楼主怎么不把 pre 加上,grep 也支持 pre 的。上次研究了半天写了一个表达式在 .net 里好用,在 pre 里面居然不行,查了下 pre 不支持变长的 zero-width negative look-behind assertion,晕过去。
    lcj2class
        4
    lcj2class  
    OP
       Dec 8, 2014
    @lsmgeb89
    pre我很少用到,Lookahead也很少用,后面我会找机会对 linux 下的 RE 做个系统的介绍的。
    matrix67
        5
    matrix67  
       Dec 8, 2014 via Android
    正则迷雾,这篇文章又讲。不过呢,正则本身太丑陋了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4829 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 77ms · UTC 09:51 · PVG 17:51 · LAX 02:51 · JFK 05:51
    ♥ Do have faith in what you're doing.