emacs regexp和perl兼容正则表达式(PCRE)的比较表? [英] comparison table for emacs regexp and perl compatible regular expression (PCRE)?

查看:172
本文介绍了emacs regexp和perl兼容正则表达式(PCRE)的比较表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个很好的表或一个比较emacs正则表达式和PCRE的sytax的表格或一个骗子?我必须记住,转义分组括号和大括号和其他差异,当我使用emacs正则表达式,这是令人困惑的,一个语法比较表将有助于最小化混乱。

解决方案

我会收集我在这里知道的语法差异。这个答案是社区wiki,如果有人愿意,添加更多。在添加更多之前,请务必检查预览。



何时逃脱(){} |



在Emacs regexp中, (,),{,},|是文字和转义的(\(,\),\ {,\},\ |)是元。



在Perl兼容的regexp中, (,),{,},|是元,逃避的是文字。



*和+



\ *是Emacs和Perl。如果一个表达式从一个明星开始,则起始星是Emacs正则表达式中的字面值,Perl正则表达式是非法的。



同样的加号。



字符类



字符类 \d (数字), \w (对于单词), \s (对于空格字符)在Emacs正则表达式中不起作用,但工作在Perl。在Emacs中,使用 [[:digit:]] [[:word:]] [[:space:]] 改为(带双括号)。在Perl中,他们也是 [:digit:] [:word:] [:space:] (单括号)。



\w 在Emacs匹配',与Perl不同,这是因为文本模式语法表有 '作为字符。



反斜杠构造



Emacs Regexp反斜杠,以下构造不是Perl兼容的正则表达式。

  \` \'\ = \< \> \_< \_> \sC \cC 

另请参见什么\<和>可以这样做\b不能做



\A \Z \z 不在Emacs中。在Emacs中,使用:

  \`或\'
pre>

关于换行符和互动使用的并发症



请参阅 Emacs中的文本模式匹配。它还提到为什么 \\\
\t 不匹配增量搜索中的换行符和标签正常表达式( CMs Mx isearch-forward-regexp )以及该如何处理。



等等



Emacswiki正则表达式


Is there a nice table or a cheatsheet on the web that compares the sytax of emacs regex and PCRE?

That I have to remember to escape grouping parenthesis and braces and other differences when I'm using emacs regex, it's all confusing, a syntax comparison table would be good for minimizing confusion.

解决方案

I will collect syntax differences that I know here. This answer is community wiki, add more if anyone wishes. Always check the preview before adding more.

When to escape ( ) { } |

In Emacs regexp, (, ), {, }, | are literal and escaped ones (\(, \), \{, \}, \|) are meta.

In Perl-compatible regexp, (, ), {, }, | are meta, and escaped ones are literal.

* and +

\* is the literal star in both Emacs and Perl. If an expression starts with a star, the starting star is literal in Emacs regexp, illegal in Perl regexp.

Similarly for the plus.

Character classes

The character classes \d (for digits), \w (for words), \s (for whitespace characters) do not work in Emacs regular expressions, but work in Perl. In Emacs, use [[:digit:]], [[:word:]], [[:space:]] instead (with double brackets). In Perl, they are also [:digit:], [:word:], [:space:] (single brackets).

\w in Emacs matches ' and " too, unlike Perl. This is because text-mode syntax table has ' and " as word characters.

Backslash constructs

Of backslash constructs mentioned in Emacs Regexp Backslash, the following constructs are NOT in Perl compatible regular expressions.

\` \' \= \< \> \_< \_> \sC \cC

See also what \< and > can do that \b cannot do

\A, \Z, \z are NOT in Emacs. In Emacs, use instead:

\` or \'

Complications regarding newlines and interactive usage

See the second section in Text Pattern Matching in Emacs. It also mentions why \n and \t don't match newlines and tabs in incremental search forward for regular expression (C-M-s or M-x isearch-forward-regexp) and what to do.

Etc

Emacswiki regular expression

这篇关于emacs regexp和perl兼容正则表达式(PCRE)的比较表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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