RegExp ? Quantifier
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 x? quantifier matches zero or one occurrences of x.
Syntax
new RegExp("x?")
or simply:
/x?/
Syntax with modifiers
new RegExp("x?", "g")
or simply:
/x?/g
Browser Support
/x?/
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |