正则表达式类型之间的差异

时间:2011-12-26 22:22:36

标签: regex syntax find posix

我正在阅读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使用什么类型的正则表达式?

1 个答案:

答案 0 :(得分:5)

正则表达式以多种方式实现。 POSIX扩展表达式知道与POSIX基本表达式相同的元字符,但有一些添加,如您所见on this page

在某些情况下,人们可能希望使用其中一个实现所知的特定元字符,您可以使用此选项告诉find您正在使用哪个元字符。 如果您只需要更基本的表达式,posix-basic就足够了。

此外,您可能更喜欢您习惯的RegEx类型,find能够正确解释它。

正如fge所提到的,使用this site来了解有关RegEx语法之间差异的更多信息。