CHARACTER MATCHING -
- .
- Match any one character
- [ ]
- Match any one character listed between the brackets
- [^ ]
- Match any one character not listed between the brackets
REPETITION OPERATORS
- ?
- Match any character one time, if it exists
- *
- Match declared element multiple times, if it exists
- +
- Match declared element one or more times
- {n}
- Match declared element one or more times
- {n,}
- Match declared element at least n times
- {n,N}
- Match declared element at least n times, but not more than N times
ANCHORS
- ^
- Match at the beginning of a line
- $
- Match at the end of a line
- \>
- Match at the beginning of a word
- <\
- Match at the end of a word
- \b
- Match at the beginning or end of a word
- \B
- Match in the middle of a word
ALTERNATION - Another handy device in REs is the alternation or infix operator. Essentially, this operator is equivalent to an inclusive OR statement and is represented by the | symbol.
RESERVED CHARACTERS - One last important concept in using basic REs is reserved characters (also called special characters). For example, if you want to look for the strings “ne*rd” and “ni*rd”, the pattern-matching statement “n[ei]*rd” will match variations of “neeeeerd” and “nieieierd” but not the strings you’re looking for. Because ‘*’ (the Kleene star) is a reserved character, you have to escape it using a backslash (\) in your pattern, like so: “n[ei]\*rd”.
Reserved characters include -
* ^ (carat)
* . (period)
* [ (left bracket}
* $ (dollar sign)
* ( (left parenthesis)
* ) (right parenthesis)
* | (pipe)
* * (asterisk)
* + (plus symbol)
* ? (question mark)
* { (left curly bracket, or left brace)
* \ backslash
(this round of regex refreshing was assisted by The Open Group’s regexp description.