JavaScript RegExp ? quantifier
The JavaScript RegExp object
Definition and Usage
nThe ? quantifier matches any string containing zero or one n the specified string.
Syntax
new RegExp("
n
?")
Or a simpler way:
/
n
?/
Browser support





All major browsers support the ? quantifier.
Example
Example
Perform a global search for "1", including zero or one "0" immediately following it:
var str="1, 100 or 1000?";
var patt1=/10?/g;
The text marked below shows where the expression found matches:
1
,
10
0 or
10
00?
Try it »
The JavaScript RegExp object