Was this helpful?
^
The caret ( ^ ) is a metacharacter that is used in regular expressions. It has two meanings depending on the context of its use.
1. When used in a simple regular expression, it matches the beginning of a line or string.
Example
/^ABC/ will match the string "ABC" at the beginning of a line or string.
/^[ABC]/ will match an A, B or C at the beginning of a line or string
2. When used in a character class, the ^ negates the character class.
Example
/[^ABC]/ will match any character other than an A, B or C
/^[^ABC]/ will match any character at the beginning of a string, except A, B or C
/^[^a-z]$/ will match any single-character string, except a lower-case letter.
For information on how they participated in this regular expression, see [ ] – and $.
Last modified date: 08/02/2023