JavaScript RegExp Quantifier

Definition and usage

n? Quantifier matches zero or one occurrences of n in any string.

Example

Global search for "1", followed by zero or one "0" character:

let text = "1, 100 or 1000?";
let pattern = /10?/g;

Try it yourself

Syntax

new RegExp("n?")

Or abbreviated as:

/n?/

Modified syntax

new RegExp("n?", "g")

Or abbreviated as:

/n?/g

Browser Support

/n?/ Is ECMAScript1 (ES1) feature.

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support