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

前端 未结 2 979
野趣味
野趣味 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:41

    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

提交回复
热议问题