正则表达式中有用但很少用的语法

  1. 转义的"尖括号" -- /<.../> -- 用于匹配单词边界

    尖括号必须被转义才含有特殊的含义, 否则它就表示尖括号的字面含义.

    "/<the/>" 完整匹配单词"the", 不会匹配"them", "there", "other", 等等. 
    bash$ cat textfile This is line 1, of which there is only one instance. This is the only instance of line 2. This is line 3, another line. This is line 4. bash$ grep 'the' textfile This is line 1, of which there is only one instance. This is the only instance of line 2. This is line 3, another line. bash$ grep '/<the/>' textfile This is the only instance of line 2.    

  2.  GNU版本的sed和awk能够使用"+",但是它需要被转义一下

    #echo a111b | sed -ne '/a1/+b/p' #echo a111b | grep 'a1/+b' #echo a111b | gawk '/a1+b/'

    上边3句的作用相同

  3.  "^$" 匹配空行

  4. [/d/D]匹配任何字符,点号.匹配换行符以外的所有字符。(Perl)

你可能感兴趣的:(正则表达式,perl)