Regular Expressions: Or
Welcome to the Or lesson!
This lesson is shown as static text below. However, it's designed to be used interactively. Click the button below to start!
Sometimes we need to allow multiple alternatives. We can separate them with a pipe character,
|, pronounced "or".>
/a|b/.test('a');Result:
true
>
/a|b/.test('b');Result:
true
>
/a|b/.test('c');Result:
false
>
/at|og/.test('cat');Result:
true
>
/at|og/.test('dog');Result:
true
>
/at|og/.test('bat');Result:
true
>
/at|og/.test('horse');Result:
false