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


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


Or escape the ^ using a backslash \:


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.