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

前端 未结 2 985
野趣味
野趣味 2020-11-30 15:10

I know these won\'t do it and also why, but how do you match it?

/^/
/(^)/
/[^]/
2条回答
  •  感情败类
    2020-11-30 15:48

    Escape it with a backslash:

    /\^/
    

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

提交回复
热议问题