Compose a regular expression from other RegExp objects
You can create a
Regexp
Show archive.org snapshot
object from existing Regexp
objects by using the interpolation syntax you know from strings:
re1 = /x/
re2 = /a#{re1}b/
'aaxbb' =~ re2 # => 1
Note
If your regular expression contains backreferences like
\1
, they may no longer refer to the correct capture group after concatentation.