小编rem*_*rem的帖子

grep : '+' 特殊字符

我用 grep '+' 和 '*' 特殊字符做了一些简单的测试

$ echo 'where wh+'> /tmp/toto
$ grep 'wh[e]\*' /tmp/toto
$ grep 'wh[e]*' /tmp/toto
where wh+
$ grep 'wh[e]+' /tmp/toto
$ grep 'wh+' /tmp/toto
$ grep 'wh[e]\+' /tmp/toto
where
$ grep -E 'wh[e]*' /tmp/toto
where wh+
$ grep -E 'wh[e]+' /tmp/toto
where wh+
Run Code Online (Sandbox Code Playgroud)

从这些测试中,非扩展 grep '+'(和 '?')不会被解释为特殊字符,为了将其用作特殊字符,必须对其进行转义。正如我所读到的,grep 使用基本正则表达式(没有 -E 选项),在这种情况下,这里定义了特殊字符:http : //pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03 和 '? ' '+' 不是 BRE 的特殊字符。

但是为什么在 BRE 中转义非特殊字符“+”会使其成为特殊字符?

grep

5
推荐指数
1
解决办法
7073
查看次数

标签 统计

grep ×1