将 Perl 正则表达式翻译成 .NET [英] Translate Perl regular expressions to .NET

查看:29
本文介绍了将 Perl 正则表达式翻译成 .NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Perl 中有一些有用的正则表达式.有没有一种简单的方法可以将它们转换为 .NET 的正则表达式方言?

I have some useful regular expressions in Perl. Is there a simple way to translate them to .NET's dialect of regular expressions?

如果没有,是否有简要的差异参考?

If not, is there a concise reference of differences?

推荐答案

http://www.regular-expressions.info/refflavors.html.

大部分基本元素都一样,区别在于:

Most of the basic elements are the same, the differences are:

细微差别:

  • Unicode 转义序列.在 .NET 中它是 u200A,在 Perl 中它是 x{200A}.
  • v 在 .NET 中只是垂直制表符 (U+000B),在 Perl 中它代表垂直空白"类.当然,Perl 中有 V 正因为如此.
  • .NET 中命名引用的条件表达式是 (?(name)yes|no),但是 (?()yes|no)在 Perl 中.
  • Unicode escape sequences. In .NET it is u200A, in Perl it is x{200A}.
  • v in .NET is just the vertical tab (U+000B), in Perl it stands for the "vertical whitespace" class. Of course there is V in Perl because of this.
  • The conditional expression for named reference in .NET is (?(name)yes|no), but (?(<name>)yes|no) in Perl.

某些元素仅适用于 Perl:

  • 所有格量词(x?+x*+x++ 等).改用非回溯子表达式 ((?>...)).
  • 命名的 unicode 转义序列 N{LATIN SMALL LETTER X}, N{U+200A}.
  • 案例折叠和转义
    • l(小写下一个字符),u(下一个大写字符).
    • L(小写)、U(大写)、Q(引用元字符)直到 E.
    • Possessive quantifiers (x?+, x*+, x++ etc). Use non-backtracking subexpression ((?>…)) instead.
    • Named unicode escape sequence N{LATIN SMALL LETTER X}, N{U+200A}.
    • Case folding and escaping
      • l (lower case next char), u (upper case next char).
      • L (lower case), U (upper case), Q (quote meta characters) until E.
      • code (?{…})
      • 递归(R)(R1)(R&name)
      • 定义(DEFINE).
      • (?P…).使用 (?...) 代替.
      • (?P=name).使用 k 代替.
      • (?P>name)..NET 中没有等效项.
      • (?P<name>…). Use (?<name>…) instead.
      • (?P=name). Use k<name> instead.
      • (?P>name). No equivalent in .NET.

      某些元素仅适用于 .NET:

      • 可变长度的后视.在 Perl 中,对于正向后视,请改用 K.
      • 条件表达式中的任意正则表达式(?(pattern)yes|no).
      • 字符类减法(未记录?)[a-z-[d-w]]
      • 平衡组(?<-name>…).这可以通过代码评估断言 (?{…}) 后跟一个 (?&name) 来模拟.
      • Variable length look-behind. In Perl, for positive look-behind, use K instead.
      • Arbitrary regular expression in conditional expression (?(pattern)yes|no).
      • Character class subtraction (undocumented?) [a-z-[d-w]]
      • Balancing Group (?<-name>…). This could be simulated with code evaluation assertion (?{…}) followed by a (?&name).

      参考文献:

      这篇关于将 Perl 正则表达式翻译成 .NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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