Regular PDF
Regular PDF
Atoms Operators
1. Atoms:
Single Character: The simplest atom is a single character. When a single character appears in a
regular expression, it matches itself. In other words, if a regular expression is made of one single
character, that character must be somewhere in the text to make the pattern match successful.
Example:$grep “HELLO” filename
Dot: A dot matches any single character except the new line character(\n).This universal
matching capability makes it a very powerful element in the operation of regular
expressions.
Example:
Class: The class atom defines a set of ASCII characters, any one of which may match any
of the characters in the text.
The character set to be used in the
matching process is enclosed in
brackets.
Example: [ABC] matches either A, B, or C.
\1 \2 .. . \9
2. OPERATORS:
To make the regular expressions more powerful, we can combine atoms with operators. The
regular expression operators play the same role as mathematical operators. Mathematical
expression operators combine mathematical atoms (data); regular expression operators combine
regular expression atoms.
We can group the regular expressions into five different categories: sequence operators,
alternation operators, repetition operators, group operators, and save operators.
Sequence operators: The sequence operator is nothing. this means that if a series of atoms ,such
as a series of characters
Alternation operators: The alternation operators( | ) is used to define one or more alternatives.
For example, if we want to select between A or B, we would code the regular expression as A|B.
EXAMPLE: UNIX| Unix =>matches “UNIX” or “unix”
repetition operators: The repetition operator is a set of escaped braces (\ {… \}).
Example: A \{3 …5 \} =>matches “AAAA, or “AAAAA”
group operators: In the group operator, when a group of characters is enclosed in parentheses, the
next operator applies to the
whole group, not only the previous characters
Example: