x_goose_x
05-05-2003, 12:34 AM
I have a string that contains the path to an image. The images are always named like x11 (a letter, then one or two digits). I want to extract the number of the image, disregarding the starting character. At first I tried the following:
myString = img.src;
alert(/[0-9]{1,2}(?:\.gif)/.exec(myString));
Where by my understanding, searches for a single or double digit, followed by ".gif", but only returns the number. This did NOT work. After playing around a bit, I tried:
myString = img.src;
alert(/[0-9]{1,2}(?=\.gif)/.exec(myString));
which works perfectly. My question is, why didn't my original code work? Am I using the ?: incorrectly?
myString = img.src;
alert(/[0-9]{1,2}(?:\.gif)/.exec(myString));
Where by my understanding, searches for a single or double digit, followed by ".gif", but only returns the number. This did NOT work. After playing around a bit, I tried:
myString = img.src;
alert(/[0-9]{1,2}(?=\.gif)/.exec(myString));
which works perfectly. My question is, why didn't my original code work? Am I using the ?: incorrectly?