Ajaxmin crunches regex in javascript incorrectly

Jun 22, 2012 at 5:55 AM

I created simple function

function HelloWorld()
var abcd = FORM[O|o]\d;

after running ajaxmin command I got

function HelloWorld(){var n=FORM[O|o];\d}

In minified javascript code regular expression is crunched in different way.

Can you please let me know whch option or setting should be disabled to keep regular expression untouched?

Jun 23, 2012 at 1:38 AM

First your code would have to be a regular expression before AjaxMin would minify it as a regular expression. Your code is incorrect: it's not valid Javascript, and certainly not a valid JavaScript regular expression. There are two ways to create a regular expression in JavaScript: regular expression literals and the RegExp contructor. If your pattern is constant (as yours is), I would always use a literal rather than the RegExp constructor. It looks like you are most of the way to creating a regular expression literal, but you've just neglected to use the right syntax. The pattern part of a regular expression literal must be delimited with forward-slashes. Your code should be:

var abcd = /FORM[O|o]\d/;

Give that a try; it always helps to have valid JavaScript first.