REGULAR EXPRESSION
It is a combination of wild cards & characters used for
pattern matching.
A wildcard can be used at any location any number of times.
Wildcards
1) . (a
dot) -> matches with any single character
Ex,
a) a.c - matches
with the following,
abc
a1c
a$c
a c
2) {n} -> matches with ‘n’ occurrences of previous
character.
Ex,
La{3} -> Laaa
(La){3} -> LaLaLa
.{3} -> matches with any 3 characters.
. . .
Abc
A$3
A12
- - - -> 3
spaces
3) {n, m} -> matches with minimum ‘n’ occurrences
& maximum ‘m’ occurrences of previous characters.
Ex,
(zup){2, 4}
Zup zup
Zup zup zup zup
4) {n, } -> matches with minimum ‘n’ occurrences
of previous characters.
Ex,
Yahoo {1, }
Yahoo
Yahoooooooooooo …. (infinity)
5) ? -> matches with 0 or 1 occurrence of previous
characters which is equivalent to {0, 1}
Ex: UFT?--à
QT , UFT
6) + -> matches with 1 or more
occurrence(infinity) of previous character equivalence to {1, }
Ex – Yahoo+
Matches Yahoo
Yahoooooooooooooooooo
…
7) * matches
with zero or more occurrences of previous character which is equivalent to {0,
}
8) .* -> matches with any character in any number
of lines
9) Set of letters within square brackets ->
matches with any single letter from the list
Ex,
[rcb]at
Matches
rat
cat
bat
Not cbat
10) within square brackets , set of digits ->
matches with any digit from the list.
Ex ,
[1, 5, 7]
Matches 1
5
7
11) Range of characters within square braces –
matches with any single letter from the range.
Ex,
[a – z]1
Matches a1
a1
..
..
..
z1
[0 – 9] -> matches with any single digit from the range 0
-9.
12) x | y
x OR y -> matches with either x or y.
Ex,
f|wood -> matches with ‘f’ or wood
(f|w)ood -> matches with food, wood