var re = /blah[/]blah/;
Now, to most people who’ve written regular expressions before, you know that
[/] is invalid because the forward slash is a metacharacter which must be escaped for use in a regular expression. This should cause a syntax error, however, every browser allows this an interprets it as if the code where
I discovered this last night when running some code through the YUI Compressor, which uses Rhino to parse the code before outputting a compressed version. This resulted in a syntax error that stopped the compression process. After some searching, I figured out this was the problem.
In my opinion, it’s browser behavior like this that makes for crappy web development practices. The more the browsers “forgive” developer mistakes, the less important it is to write good code. If there’s no benefit to writing good code, people won’t do it.