JavaScript RegExp ? Quantifier
Example
Do a global search for a "1", followed by zero or one "0" characters:
let text = "1, 100 or 1000?";
let pattern = /10?/g;
Try it Yourself »
Description
The n? quantifier matches any string that contains zero or one occurrences of n.
Browser Support
/n?/
is an ECMAScript1 (JavaScriopt 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
new RegExp("n?")
or simply:
/n?/
Syntax with modifiers
new RegExp("n?", "g")
or simply:
/n?/g