Differences between regex types

自闭症网瘾萝莉.ら 提交于 2020-01-12 07:03:14

问题


I'm reading the GNU find's man page and stumbling upon this switch:

-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.

What's the difference between those regex syntaxes? I'm more familiar with Ruby's regex, so what type of regex should I use with find?


回答1:


Regular expressions are implemented in many ways. POSIX Extended Expressions know the same metacharacters as POSIX Basic Expressions but with a few additions as you can see on this page.

In some cases one might want to use a certain metacharacter known by one of those implementations and you can use this option to tell find which one you are using. If you only need a more basic expression, posix-basic would be enough.

Also you might just prefer the type of RegEx you are used to and find is able to interpret it correctly.

As fge mentioned, use this site to learn more about the differences between RegEx syntactics.



来源:https://stackoverflow.com/questions/8639519/differences-between-regex-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!