Regular Expressions Anchor Characters: Caret (^) Escaping the caret character


Example

If you need to use the ^ character in a character class (Character classes ), either put it somewhere other than the beginning of the class:

[12^3]

Or escape the ^ using a backslash \:

[\^123]

If you want to match the caret character itself outside a character class, you need to escape it:

\^

This prevents the ^ being interpreted as the anchor character representing the beginning of the string/line.