pickle wrote:I'm guessing that the !year.test(start_year) line is causing the error. The way you've got it set up, year isn't an object, so test can't be a function of it.
Heh.... Actually JavaScript supports a "regexp" object. Just like string objects.
You can explicitly declare:
Code: Select all
var year = new RegExp('pattern', 'modifiers');
Or you can just jump in and do it
Then test() is actually a method of the regexp object "year.test(strint_to_test_against);". It returns true or false if the regex matches pattern. Another method is exec().
JS is a bit scattered with RegExp though, because you can do things another way too.... there are string methods which take a regex object as an argument (match(), replace()....)
Code: Select all
var foo = "a number: 123";
document.write( foo.replace( /^([a-z\s]+:\s*)(\d+)$/i, "$1XXX") ); //a number: XXX
I think that's right (*hopes*)
