JavaScript RegExp [0-9] Expression
Example
Do a global search for the numbers 1, 2, 3 and 4 in a string:
var str = "123456789";
var patt1 = /[1-4]/g;
Try it Yourself »
Definition and Usage
The [0-9] expression is used to find any character between the brackets.
The digits inside the brackets can be any numbers or span of numbers from 0 to 9.
Tip: Use the [^0-9] expression to find any character that is NOT a digit.
Browser Support
Expression | |||||
---|---|---|---|---|---|
[0-9] | Yes | Yes | Yes | Yes | Yes |
Syntax
new RegExp("[0-9]")
or simply:
/[0-9]/
Syntax with modifiers
new RegExp("[0-9]", "g")
or simply:
/\[0-9]/g
More Examples
Example
Do a global search for the number "1" in a string:
var str = "12121212";
var patt1 = /[1]/g;
Try it Yourself »