Just a small question:
I’m trying to make my code JSLint errorfree, but ran into this problem:
Unexpected ‘\d’. (in both of the regex’s)
hourduration = parseInt(activity.endTime.replace(":\d\d", ""), 10) - parseInt(activity.startTime.replace(":00", ""), 10);
minuteduration = (parseInt(activity.endTime.replace("(\d)?\d:", ""), 10) - parseInt(activity.startTime.replace(":00", ""), 10)) / 60;
What can I do to improve my regex so that jslint will validate it?
Thanks!
Solution:
hourduration = parseInt(activity.endTime.replace(/:\d\d/, ""), 10) - parseInt(activity.startTime.replace(":00", ""), 10);
minuteduration = (parseInt(activity.endTime.replace(/(\d)?\d:/, ""), 10) - parseInt(activity.startTime.replace(":00", ""), 10)) / 60;
JSLint wants you to use a RegExp object or a
/regex/‘string’, not a normal string:EDIT: All examples are valid, but the last 2 are the official way of working with regexes.