Hope This Helps
From Sams Book Teach Yourself Regular Expressions In 10 Minutes
Matching Digits (and Nondigits)
[0-9] is a shortcut for [0123456789] and is used to match any digit. To match anything other than a digit, the set can be negated as [^0-9]. Table 4.2 lists the class shortcuts for digits and nondigits.
Table 4.2. Digit Metacharacters Metacharacter
Description
\d
Any digit (same as [0-9])
\D
Any nondigit (same as [^0-9])
To demonstrate the use of these metacharacters, let's revisit a prior example:
var myArray = new Array();
...
if (myArray[0] == 0) {
...
}
myArray\[\d\]
var myArray = new Array();
...
if (myArray[0] == 0) {
...
}
\[ matches [, \d matches any single digit, and \] matches ], so that myArray\[\d\] matches myArray[0]. myArray\[\d\] is shorthand for myArray\[0-9\], which is shorthand for myArray\[0123456789\]. This regular expression would also have matched myArray[1], myArray[2], and so on (but not myArray[10]).
Last edited by speakingtohe; 04-24-2010 at 03:37 AM.
|