I’ve seen some posts about JSLint “bad escapement” warnings, but I just wanted to see if I’m doing this Regex correctly. (Note – I’m dabbler programmer).
I have a function (below) that attempts to parse out a variable from it’s name in a long message. The regex is working well, but should I change something in response to the JSLint warning?
A very simplified version of msg could look like this essentially:
VariableName1 = Value1
VariableName2 = Value2
VariableName3 = Value3
The actual msg has different unstructured data above and below. I had to use a strange Regex since even though a more simple one worked on all the testing websites, it didn’t work within the server application we are using, so this is the only way I could get it to work. The regular expression incorporates a variable.
Here is the parsing function I’m using:
function parseValue(msg, strValueName) {
var myRegexp = new RegExp(strValueName + ' = ([A-Z3][a-zA-Z\. 3]+)[\\n\\r]+', 'gm');
log('parseValue', 'myRegexp = ' + myRegexp.toString());
var match = myRegexp.exec(msg);
log('parseValue', 'returning match = ' + match[1] );
return match[1];
}
There is probably something much simpler that a ‘real’ programmer can come up with pretty easily. Any help would be appreciated.
THanks.
The problem that JSLint didn’t like was the ‘.’ character in the character class as pointed out by ‘Explosion Pills’.
When I removed the ‘.’ all was good.
Thanks.