开发者

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

开发者 https://www.devze.com 2022-12-23 13:18 出处:网络
Are regular expressions the same for PHP, MySQL, JavaScript, Perl, and so on? If so, is there a ch开发者_运维技巧art or tutorial that explains regular expressions?No, there often are subtle difference

Are regular expressions the same for PHP, MySQL, JavaScript, Perl, and so on? If so, is there a ch开发者_运维技巧art or tutorial that explains regular expressions?


No, there often are subtle differences in supported features (mostly of the pretty advanced kind1). For example, JavaScript regular expressions don't have lookbehind. PHP uses either POSIX extended regular expressions or PCRE (Perl-compatible regex), which are close to Perl's feature-set. In fact, Perl is probably the ancestor of many advanced features in today's regular expression engines.

As for tutorials and comparisons the site http://regular-expressions.info is a very good resource.

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; I usually use Windows PowerShell but Ruby or Python are also pretty popular.


1 Thanks, 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.


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. And I think it's a good read for any of them, not just Perl.

And what do you know, "Sample Chapter 3" is available as a download from this page: Minimal Perl book!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号