I need to be able to include some arbitrary text as input into a regular
expression and I’m looking for a way to escape regular expression
metacharacters within my data(e.g. escape a “?” for example).
Is there a library somewhere that has this function available?
I need to be able to include some arbitrary text as input into a regular
expression and I’m looking for a way to escape regular expression
metacharacters within my data(e.g. escape a “?” for example).
Is there a library somewhere that has this function available?
I need to be able to include some arbitrary text as input into a
regular
expression and I’m looking for a way to escape regular expression
metacharacters within my data(e.g. escape a “?” for example).
Escapes any characters that would have special meaning in a
regular expression. Returns a new escaped string, or self if no
characters are escaped. For any string, Regexp.escape(str)=~str
will be true.
Regexp.escape('\*?{}.') #=> \\*\?\{\}\.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.