I need to convert string like "/[ws]+/" to regular expression.
"/[ws]+/" => /[ws]+/
I tried using different Regexp
methods like:
Regexp.new("/[ws]+/") => //[w ]+//
, similarly Regexp.compile
and Regexp.escape
. But none of them returns as I expected.
Further more I tried removing backslashes:
Regexp.new("[ws]+") => /[w ]+/
But not have a luck.
Then I tried to do it simple:
str = "[ws]+"
=> "[w ]+"
It escapes. Now how could string remains as it is and convert to a regexp object?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…