我正在读《GNU》find
的手册页并偶然发现了这个开关:
-regextype type
Changes the regular expression syntax understood by -regex and
-iregex tests which occur later on the command line. Currently-
implemented types are emacs (this is the default), posix-awk, posix-
basic, posix-egrep and posix-extended.
这些正则表达式语法有什么区别?我更熟悉 Ruby 的正则表达式,所以我应该使用什么类型的正则表达式find
?
正则表达式有多种实现方式。 POSIX 扩展表达式与 POSIX 基本表达式具有相同的元字符,但如您所见,还添加了一些内容在本页 http://en.wikibooks.org/wiki/Regular_Expressions/syntax/posix_extended_regular_expression.
在某些情况下,人们可能想要使用这些实现之一已知的某个元字符,您可以使用此选项来告诉find
您正在使用哪一款。
如果你只需要更基本的表达,posix-basic http://en.wikibooks.org/wiki/Regular_Expressions/syntax/posix_basic_regular_expression就足够了。
另外,您可能只是更喜欢您习惯的正则表达式类型,并且find
能够正确地解释它。
正如所提到的,使用这个网站 http://www.regular-expressions.info/refflavors.html了解有关正则表达式语法之间差异的更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)