简体   繁体   English

用于PHP,MySQL,JavaScript,Perl等的正则表达式引擎有多相似?

[英]How similar are the Regular expressions engines for PHP, MySQL, JavaScript, Perl, etc?

Are regular expressions the same for PHP, MySQL, JavaScript, Perl, and so on? PHP,MySQL,JavaScript,Perl等的正则表达式是否相同? If so, is there a chart or tutorial that explains regular expressions? 如果是这样,是否有解释正则表达式的图表或教程?

No, there often are subtle differences in supported features (mostly of the pretty advanced kind 1 ). 不,支持的功能通常存在细微的差异(大多数是高级功能1 )。 For example, JavaScript regular expressions don't have lookbehind. 例如,JavaScript正则表达式没有落后。 PHP uses either POSIX extended regular expressions or PCRE (Perl-compatible regex), which are close to Perl's feature-set. PHP使用POSIX扩展正则表达式或PCRE(与Perl兼容的正则表达式),它们接近Perl的功能集。 In fact, Perl is probably the ancestor of many advanced features in today's regular expression engines. 实际上,Perl可能是当今正则表达式引擎中许多高级功能的始祖。

As for tutorials and comparisons the site http://regular-expressions.info is a very good resource. 至于教程比较http: //regular-expressions.info网站是一个很好的资源。

Once you got used to writing and applying them it often is helpful to just quickly try out things. 一旦习惯了编写和应用它们,通常对快速尝试一下很有帮助。 I have found a REPL to be quite handy; 我发现REPL非常方便。 I usually use Windows PowerShell but Ruby or Python are also pretty popular. 我通常使用Windows PowerShell,但是Ruby或Python也很流行。


1 Thanks, Dancrumb . 1谢谢, Dancrumb

In theory regular expression is a language for pattern matching.But there are little differences from language to language . 理论上,正则表达式是一种用于模式匹配的语言。但是,语言之间几乎没有什么区别。 My advice is use a tool like Regex Coach to building/learning regular expressions. 我的建议是使用Regex Coach之类的工具来构建/学习正则表达式。

There is an excellent write-up of Perl regular expressions compared to "classic", POSIX and GNU grep in Chapter 3 of the book "Minimal Perl" by Tim Maher. 与Tim Maher在“ Minimal Perl”一书的第3章中相对于“经典”,POSIX和GNU grep相比,Perl正则表达式写得很好。 And I think it's a good read for any of them, not just Perl. 而且我认为这对任何人来说都是不错的选择,而不仅仅是Perl。

And what do you know, "Sample Chapter 3" is available as a download from this page: Minimal Perl book ! 您可以从此页面下载“ Sample Chapter 3”(样本第3章): Minimal Perl book

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM