Regular Expression - (ab|cd) - matches ab or cd

The round brackets and pipe symbol (( | )) match longer alternatives. Each of the alternatives presented can be single or multiple characters.

Examples

Match either this or that:

(this|that)
This would match the following:
this
that
Note that this could be expressed as follows (although less clearly):
th(is|at)
It would not match the following:
thai - has to be this or that
thit - has to be this or that

Computing Articles