JavaScript RegExp (x|y) Expression
Example
Do a global search to find any of the specified alternatives (red|green):
var str = "re, green, red, green, gren, gr, blue, yellow";
var patt1 = /(red|green)/g;
Try it Yourself »
Definition and Usage
The (x|y) expression is used to find any of the alternatives specified.
The alternatives can be of any characters.
Browser Support
Expression | |||||
---|---|---|---|---|---|
(x|y) | Yes | Yes | Yes | Yes | Yes |
Syntax
new RegExp("(x|y)")
or simply:
/(x|y)/
Syntax with modifiers
new RegExp("(x|y)", "g")
or simply:
/(x|y)/g
More Examples
Example
Do a global search to find any of the specified alternatives (0|5|7):
var str = "01234567890123456789";
var patt1 = /(0|5|7)/g;
Try it Yourself »