Special Characters

2 min read ·

Special characters in regular expressions have specific meanings and allow powerful pattern matching.

Dot .

The dot matches any single character except newline.
Matches:
  • cat

Caret ^

The caret matches the start of the string.

Dollar $

The dollar symbol matches the end of the string.

Star *

Matches zero or more occurrences of previous character.
Matches:
  • col
  • cool
  • coool

Plus +

Matches one or more occurrences of previous character.
Matches:
  • cool
  • coool

Question Mark ?

Matches zero or one occurrence of previous character.
Matches:
  • color
  • colour

Note

Special characters change the meaning of patterns and are not treated as normal text.


Combining Special Characters

Matches:
  • cat

Pro Tip

Understanding special characters is key to writing powerful regex patterns.


Caution

Incorrect use of special characters can lead to unexpected matches.


Exercise

  • Match words ending with "ing"
  • Match words starting with "P"
  • Find patterns using . wildcard
  • Try *, +, ? with different words