JavaScript RegExp ?Quantifier
JavaScript RegExp Object
Definition and Usage
nThe ? quantifier matches any string containing zero or onenof the preceding character.
Syntax
new RegExp("n?")
Or a simpler way:
/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;
var patt1=/10?/g;
Belowmarkedtext shows where the expression gets a match:
1, 100 or 1000?
Try it Yourself »
JavaScript RegExp Object Other Extensions