Character and Position Matching
a matches the single character "a"
. matches any character
\. matches only "." and no other character
^ matches the beginning of the text
$ matches the end of the text
[[:<:]] matches the point between the last non-word character and the beginning of a word
[[:>:]] matches the point between the last character of a word and the following non-word character
Examples
gigo matches "gigo", "gigoit" or "gigoit.org"
^gigo matches "gigoit" but not "http://www.gigoit.org"
it$ matches "gigoit" but not "http://www.gigoit.org"
. matches any single character
.n matches "an", "on", "3n", etc.
[[:<:]]it matches "it" but not "gigoit" (no letters before "it")
gigo[[:>:]] matches "gigo" but not "gigoit" (no letters after "gigo")
[[:<:]]gigo[[:>:]] matches "gigo" but not "gigoit" or "www.gigoit.org"
Character Class
[ begins a character class
] ends a character class
^ used inside square brackets, it negates the character class
- used inside square brackets, it separates the beginning and end of a range
Examples
[abc] matches one of "a", "b", or "c"
[abc][abc] matches the "ac" in "action", but not any part of "auction"
[Gg]igoit matches "Gigoit" or "gigoit"
gigo[^it] matches "gigo" or "gigo it " or "gigo-it", but not "gigoit"
[x-zX-Z] matches one of "x", "y", "z", "X", "Y" or "Z"
Alternation
| matches nothing on its own, but lets the regex match if either the pattern before or after matches
Examples
gigo|it matches any string containing either "gigo" or "it"
GIGOIT|gigoit matches "GIGOIT" or "gigoit", but not "Gigoit"
GIGOIT|gigoit|Gigoit matches any of "GIGOIT", "gigoit", or "Gigoit"
Repetition Operators
? matches zero or one of the preceding character or sequence
* matches zero or more (any number) of the preceding character or sequence
+ matches one or more of the preceding character or sequence
Examples
gigo-?it matches "gigoit" or "gigo-it"
[Gg]igo-?it matches "Gigoit", "Gigo-it", "gigoit", or "gigo-it"
app.*s matches "apps", "apples", "applications" , "application forms", etc.
cho+se matches "chose" or "choose" (or "choooooose")
Sequence Grouping
( matches nothing on its own; delimits the beginning of a sequence
) matches nothing on its own; delimits the end of a sequence
Examples
gigo(it)? matches "gigo" or "gigoit" but not "gigo-it"
(gigo|Gigo)[^it] matches "gigo" or "Gigo", but not "gigoit" or "Gigoit"
(Gigo.*|gigo.*).(Org|org) "matches "gigoit.org" or "gigoit.org", among others