跨语言的 RegEx 标准 [英] RegEx standards across languages

查看:34
本文介绍了跨语言的 RegEx 标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问这个问题是因为我注意到不同语言之间的 RegEx 语法存在一些细微差别.

I am asking this question because I notice there are some slight differences in the syntax of RegEx between different languages.

我想知道是否有在某处维护的 RegEx 标准?如果是这样,我在哪里可以找到这份文件?另外,如果我在 .NET 中创建一个 RegEx 表达式,是否可以保证相同的表达式 100% 兼容并与其他语言(例如 Perl、Javascript 或 Java)兼容?

I am wondering if there is a RegEx standard that is maintained somewhere? And if so, where can I find this document? Also, if I create a RegEx expression in .NET, is the same expression guaranteed to be 100% compatible and work with other languages, such as Perl or Javascript or Java?

最后,在使用 RegEx 时是否有任何最佳实践"可以帮助使其在其他平台语言中更易于维护?

Finally, are there any "best practices" when it comes to using RegEx that can help to make it more maintainable across other platform languages?

推荐答案

最古老的标准化正则表达式集之一是 POSIX BRE(基本正则表达式)和 ERE(扩展正则表达式),记录在 正则表达式.

One of the oldest sets of standardized regular expressions are the POSIX BRE (basic regular expressions) and ERE (extended regular expressions), documented under Regular Expressions.

其他语言可能会定义自己的标准.例如,C++ 2011 在第 28 条中定义了一个正则表达式库(大约 46 页标准).Perl 定义了它的正则表达式.其他语言借鉴了这些来源和其他来源.Lex 和 Flex 使用他们自己的一组正则表达式.Sed 在正则表达式上使用自己的变体.和 Java、JavaScript 和...定义自己的版本,有时使用 PCRE(Perl 兼容的正则表达式)作为他们设计的基础.某些细节受到使用正则表达式的语言所提供的便利的影响.

Other languages may define their own standards. For example, C++ 2011 has a regular expression library defined in clause 28 (about 46 pages of standard). Perl defines its regular expressions. Other languages borrow from these sources and others. Lex and Flex use their own set of regular expressions. Sed uses its own variant on regular expressions. And Java, JavaScript, and ... define their own versions, sometimes using PCRE (Perl-Compatible Regular Expressions) as the basis for their design. Some of the details are affected by the facilities provided by the language in which the regular expressions are being used.

Jeff Friedl 的书掌握正则表达式涵盖了许多不同的正则表达式集,确定了哪些是共同的,哪些是不同的.

Jeff Friedl's book Mastering Regular Expressions covers a lot of different sets of regular expressions, identifying what's common and what's different.

这篇关于跨语言的 RegEx 标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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