问题
I know these won\'t do it and also why, but how do you match it?
/^/
/(^)/
/[^]/
回答1:
Escape it with a backslash:
/\^/
This will make it be interpreted as a literal ^
character.
回答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
来源:https://stackoverflow.com/questions/5524583/how-do-you-match-a-caret-symbol-in-regex