有没有一种方法可以使用无需正则表达式的方式查找确切的字符串,例如如果我想要查找(字面上):
/some/file"that/has'lots\of"invalid"chars/and.triggers$(#2)[*~.old][3].html
我不想逐个转义每一个可转义的字符。本质上,我想像使用echo
一样传递它:
$ echo "/some/file\"that/has'lots\of\"invalid\"chars/and.triggers$(#2)[*~.old][3].html"
/some/file"that/has'lots\of"invalid"chars/and.triggers$(#2)[*~.old][3].html
fgrep 'preg_replace("/([a-z]+)([A-Z])/"' . -R
完美运行(而grep
则失败)。你仍然需要转义$
,但这是可以接受的。 - Nathan J.B.grep -F
,“以egrep
或者fgrep
的方式直接调用已经被弃用了”。fgrep(1) - Linux man page - Lily Finley