且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中使用.net正则表达式

更新时间:2022-11-14 21:21:29

.NET正则表达式中的大多数功能都可以在Python中使用;但是缺少一些东西:

Most of the features in .NET regexes are available in Python; however there are a few things missing:

  1. Python在后面的内部不支持变量重复,仅支持固定长度.
  2. Python对命名捕获使用不同的语法.
  3. Python对Unicode字符的匹配方式不同.
  4. Python没有原子组(?> ...)或所有格限定词 ++ * + ?+ .
  5. 在Python中,将 r"..." 原始字符串用于正则表达式,否则您将遇到反斜杠.
  1. Python doesn't support variable repetition inside lookbehinds, only fixed-length.
  2. Python uses a different syntax for named captures.
  3. Python matches Unicode characters differently.
  4. Python doesn't have atomic groups (?>...) or possessive quantifiers ++, *+, ?+.
  5. In Python, use r"..." raw strings for regular expressions, or you'll trip up on backslashes.

全面的差异列表可以在此处找到.

如果您需要经常进行正则表达式转换,则 RegexBuddy 可以为您做到(只要您当然,不使用目标正则表达式引擎不具备的功能.

And if you need to do regex conversions often, RegexBuddy can do it for you (as long as you're not using features the destination regex engine doesn't have, of course).