Organizational Research By

Surprising Reserch Topic

how to use Alternation of patterns with regular-exp?


Using character classes is a way of indicating that either one thing or another thing can occur in a particular spot. But what if you want to specify that either of two whole subexpressions occur in a position in the regular expression? For that, you use the alternation operator, the vertical bar ("|"). This is the symbol that is also used to indicate a pipe in Unix/DOS shells, and is sometimes called the pipe character.

The pipe character in a regular expression indicates an alternation between everything in the group enclosing it. What this means is that even if there are several groups to the left and right of a pipe character, the alternation greedily asks for everything on both sides. To select the scope of the alternation, you must define a group that encompasses the patterns that may match. The example illustrates this.

asked Sep 13, 2013 in Regular-exp by rajesh
edited Sep 12, 2013
0 votes
21 views



Related Hot Questions



Government Jobs Opening


...