In regex, some characters have special meanings as we will explore across the chapters:
.— Literal only within character classes.1
-— Sometimes a special character within character classes.
When we wish to match these characters literally, we need to “escape” them.
This is done by prefixing the character with a
The first and last asterisks are literal since they are escaped —
The asterisk inside the character class does not necessarily need to be escaped1, but I’ve escaped it anyway for clarity.
The asterisk immediately following the character class indicates repetition of the character class, which we’ll explore in chapters that follow.
- Many special characters that would otherwise have special meanings are treated literally by default inside character classes.↩