So I had a fun hour this morning.

If you’re unaware, any javascript that’s returned via ajax (XMLHttpRequest) which is embedded in the returned text isn’t executed which is a bit of a problem.

To ‘fix’ this, I wrote a little function in the ajax class that takes the returned text, finds any javascript blocks and eval()s them. The problem is the regex. My first instinct was to write this:

source_code.match( new RegExp( “<script\\s+?type=['\"]text/javascript['\"]>(.+?)</script>”, “i” ) )

However that didn’t work. After some tweaking it seemed that ( .+?) wasn’t matching across newlines. A quick search on the internet informed that RegExp’s dot character doesn’t match across newlines and I should use ([^]+?) instead ([^] being match every character except (none)).

I made the changes and everything snapped into place, so I figured I’d quickly blog about it so that I won’t forget in the future.