正则表达式类型之间的差异 [英] Differences between regex types

查看:114
本文介绍了正则表达式类型之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读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基本表达式具有相同的元字符,但您可以在上看到一些附加字符.此页面.

在某些情况下,您可能想使用这些实现之一已知的某种元字符,并且您可以使用此选项来告诉find您正在使用哪个. 如果您只需要一个更基本的表达式,则 posix-basic 就足够了. /p>

此外,您可能只喜欢惯用的RegEx类型,并且find能够正确解释它.

如fge所述,请使用本网站来了解有关RegEx语法之间差异的更多信息

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?

解决方案

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.

这篇关于正则表达式类型之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆