How to escape all characters with special meaning in Regex

后端 未结 2 572
星月不相逢
星月不相逢 2021-01-24 14:23

I just stumbled upon the following which I can\'t quite get my head around. When you create a new Regexp in Ruby like so:

Regexp.new(\'http://www.example.com\')
         


        
2条回答
  •  既然无缘
    2021-01-24 14:55

    You can do:

    Regexp.escape('http://www.example.com')
    

    That will return the fully escaped string

提交回复
热议问题