BASICS

Escaping

A backslash tells the engine to treat the next character as a literal.

A handful of characters have a special job in a pattern. The dot is one: it means "any character" instead of a literal dot. These special characters are called metacharacters. So 3.14 does not mean the text "3.14" - the dot matches anything, so it also matches "3414" or "3x14".

To turn off that special job and match the character itself, put a backslash in front of it. The backslash says treat the next character literally. So 3\.14 matches only a real dot, giving you the exact text "3.14".

The metacharacters that need escaping when you want them literally: . * + ? ^ $ ( ) [ ] { } | \. When in doubt, escaping a punctuation character is always safe.

PRACTICE - 3 DRILLS 0/3 DONE
DRILL 1/3

Match the exact text 3.14 - and nothing that merely looks like it.

/ /
pi is 3.14 roughly
must match: "3.14"
the code 3414 is not pi
must match nothing
3x14 is not pi either
must match nothing
DRILL 2/3

Match the exact domain www.site.com. Both dots must be real dots, not any-character.

/ /
go to www.site.com today
must match: "www.site.com"
wwwxsitexcom is not it
must match nothing
visit example.org instead
must match nothing
DRILL 3/3

Match the exact price $5.00. Both the dollar sign and the dot are metacharacters here, so escape them.

/ /
it costs $5.00 total
must match: "$5.00"
5500 cents is not it
must match nothing
price is $5x00 maybe
must match nothing
the total $500 differs
must match nothing