(其他引用/ grep问题与bash解释有关,不是)
显然,grep
转义的单引号与其他转义的正则表达式字符的处理方式不同,但我不明白为什么。
$ grep --version
grep (GNU grep) 2.25
$ cat data
a']
b']
c']
d]
e\']
$ cat patterns
a']
b\'\]
c'\]
d\']
e\']
$ grep -Ef patterns data
a']
c']
因为c
匹配但b
不匹配,因此显然grep不会将转义的单引号解释\'
为单引号。但是那又怎样呢?
d
不匹配,因此不会被忽略。e
不匹配,因此不按字面意义使用TIA解决了这个圣诞节的奥秘!PS。是的,在这种情况下,我可以使用-F进行文字匹配,但是我的应用程序需要使用正则表达式。
\'
在GNU工具中的意思是“字符串结尾”。参见http://www.regular-expressions.info/gnu.html:
Additional GNU Extensions
....
The anchor \` (backtick) matches at the very start of the subject string,
while \' (single quote) matches at the very end.
不要问我为什么他们引入了它,因为它似乎与完全相同$
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句