How do I find the number in line number may not be in the beginning. For example: "d: \ \ 1.jpg"
Thank you.
How do I find the number in line number may not be in the beginning. For example: "d: \ \ 1.jpg"
Thank you.
You can use a regexp:
var match = "testing 123".match(/\d/);
if (match) {
alert(match.index); // alerts 8, the index of "1" in the string
}
That uses String#match, passing in a literal regexp using the "digit" class (\d).
And/or you can grab all contiguous digits starting with the first digit found:
var match = "testing 123".match(/\d+/);
if (match) {
alert(match.index); // alerts 8, the index of "1" in the string
alert(match[0]); // alerts "123"
}
Those links are to the Mozilla documentation because it's fairly good, but these are not Mozilla-specific features.