How do you match a caret (^) symbol in regex?

Solution 1:

Escape it with a backslash:

/\^/

This will make it be interpreted as a literal ^ character.

Solution 2:

I think this works (I've tested this in java):

\\^

'\' is used as an escape character, so you first escape '^', then you escape '\' itself

you can find more information here: http://www.regular-expressions.info/characters.html