Regexes in Detail
In the upcoming sections, the following sample phrase is used for illustration:
  "The ships were loaded with all these belongings of the mother"
This phrase will be used to demonstrate various regex concepts, including literal characters, word boundaries, character classes, and others.
Literal Characters
The simplest regex is one of more literal characters, such as the
. This indicates a pattern that is a match if the t
character is immediately followed by h
and finally an e
character. This expression would have four matches in the sample phrase: the initial the
, the second to last word, the
, the
in the word these
, and the sequence of the
as part of the word mother
.
Special Characters, Anchors, and Escaping
If a regex only had literals, its usefulness would be limited. In most cases, you do not want to only match literals; therefore, regexes have a number of characters that have special meanings. These are also known as metacharacters...