I save some RegExps in the object as strings, but I get the above error message.
I believe this is due to the fact that they do not have a prefix / or have a suffix //, since I run them in the new RegExp () constructor, since the script allows users to define RegExps, so I want them all to be dynamic.
var patterns = {
email: '^[a-zA-Z0-9.!
url: '[-a-zA-Z0-9@:%._\+~
number: '^[-+]?[0-9]*\.?[0-9]+$',
empty: '^\\s*$'
};
Here are the lines above.
To fix them, I can do this and // them:
var patterns = {
email: '/^[a-zA-Z0-9.!
url: '/[-a-zA-Z0-9@:%._\+~
number: '/^[-+]?[0-9]*\.?[0-9]+$',
empty: '/^\\s*$/'
};
But when called through new RegExp(), of course, they will do it (for example):
var reg = new RegExp(patterns.empty);
With a double slash. My question, as a newbie to RegExp, is these double dictionaries? This can be fixed in a different way. JSHint complains because it is not a "real" RegExp.
true RegExps, , . .