Method: Regexp#interpolate
- Defined in:
- lib/innate/regexp.rb
#interpolate(replace, new_pattern) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/innate/regexp.rb', line 2 def interpolate replace, new_pattern r = /^\(\?([imx]*)(-[imx]+)?:(.*?)#{Regexp.escape replace}(.*)\)$/ m = r.match self.to_s if m s = "#{m[3]}#{new_pattern}#{m[4]}" o = m[1] || '' self.class.new(s, (o.include?(?i) ? Regexp::IGNORECASE : 0) | (o.include?(?m) ? Regexp::MULTILINE : 0) | (o.include?(?x) ? Regexp::EXTENDED : 0)) else self end end |