How to write a safe RegExp for Opera

The PHP recipe for Chili contains a big regular expression (32862 chars) to account for the thousands of PHP functions.

Internet Explorer and Firefox accept such a giant, but Opera does not. No way. It’s a problem at the core level. So the only solution, very simple though, is not to use a literal expression: use new RegExp( "..." ); instead of /.../.

Remember to escape the expression for strings: for my recipe it was very simple because the step only contains a long list of words, between two word boundaries, which need an extra backslash.

Leave a Reply

Your email address will not be published. Required fields are marked *