1Literal characters
The simplest regex is plain text: it finds exactly those characters.
A regular expression (regex) is a small pattern that describes text. The simplest pattern is just ordinary text: the regex cat finds the three characters c, a, t in that order, wherever they appear – in cat, in concatenate and in the cat sat.
Matching is case sensitive by default: cat does not match Cat. (You will meet the i flag that changes this later.)
Some characters have a special meaning and are called metacharacters: . ^ $ * + ? ( ) [ ] { } | \. To match one of them literally, put a backslash in front of it: 1\+1=2 matches the text 1+1=2.
Try it: type in the box below. Every line on the left must be matched, no line on the right may be matched. The checks update as you type.
Exercises
Lesson complete – well done!