JavaScript RegExp (x|y) Expression
Clash Royale CLAN TAG#URR8PPP
googletag.cmd.push(function() googletag.display('div-gpt-ad-1422003450156-2'); );
JavaScript RegExp (x|y) Expression
❮ JavaScript RegExp Object
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;
<!--
The marked text below shows where the expression gets a match:
re, green, red, green, gren, gr, blue, yellow
-->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;
<!--
The marked text below shows where the expression gets a match:
01234567890123456789
-->Try it Yourself »
❮ JavaScript RegExp Object