Jan 06 2010

[JavaScript] PHP PCRE_DOT_ALL option emulation in JavaScript

Category: Articles,JavaScriptFractalizeR @ 2:06 pm

Writting my WP-SynHighlight WordPress plugin, I came to a need of parsing multilined shortcode like this:

[ codesyntax option1=”optionvalue1″…] <many lines here….> [ / codesyntax]

So, I extracted regular expression to parse shortcode from WordPress source code (if you are interested in it, see /wp-includes/shortcodes.php file). This regex was executed with /s option (PCRE_DOT_ALL) which makes dot (“.”) to match newlines also. There is no such option in JavaScript for some reason and I had to replace dot by such character class:

[\S\s]

Actually, any opposite metacharacters should work. [\W\w] for example.

Quite easy, isn’t it? 🙂

Tags: , ,

Leave a Reply

You must be logged in to post a comment. Login now.