Method: Regexp.quote
- Defined in:
- re.c
.escape(string) ⇒ Object
Returns a new string that escapes any characters that have special meaning in a regular expression:
s = Regexp.escape('\*?{}.') # => "\\\\\\*\\?\\{\\}\\."
For any string s
, this call returns a MatchData object:
r = Regexp.new(Regexp.escape(s)) # => /\\\\\\\*\\\?\\\{\\\}\\\./
r.match(s) # => #<MatchData "\\\\\\*\\?\\{\\}\\.">
4191 4192 4193 4194 4195 |
# File 're.c', line 4191 static VALUE rb_reg_s_quote(VALUE c, VALUE str) { return rb_reg_quote(reg_operand(str, TRUE)); } |