Escaping regex string

后端 未结 4 1848
时光说笑
时光说笑 2020-11-22 00:36

I want to use input from a user as a regex pattern for a search over some text. It works, but how I can handle cases where user puts characters that have meaning in regex?<

4条回答
  •  广开言路
    2020-11-22 01:15

    Please give a try:

    \Q and \E as anchors

    Put an Or condition to match either a full word or regex.

    Ref Link : How to match a whole word that includes special characters in regex

提交回复
热议问题