JavaScript Regular Expression OR

To specify an “OR” condition in JavaScript regular expressions, use the pipe character – |.

var StringToTest = “abc”;
var IsFound = /a|b/.test(StringToTest);
alert(IsFound);

The above statement returns true if ‘a’ or ‘b’ is in the test string.

One Response

Leave a Reply