Project

General

Profile

Actions

Feature #12700

open

regexg heredoc support

Added by gam3 (Allen Morris) over 7 years ago. Updated over 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:77035]

Description

There is support for ', ", and ` heredocs, but there is no support for /.

Example code with new feature:

first = 'first'

orig = /#{first}
match\s # match
this    # match this
/x

right = <</REGEXP/x
#{first}
match\s # match
this    # match this
REGEXP

raise unless orig == right

There is no straight forward way to replace a regexp heredoc as a double quote heredoc requires that '\s' be escaped.
As shown in the code below you can't use the string heredoc to directly replace a regexp heredoc because of this need for extra escaping.

first = 'first'

orig = /#{first}
match\s # match
this    # match this
/x

wrong = Regexp.new(<<REGEXP, Regexp::EXTENDED)
#{first}
match\s # match
this    # match this
REGEXP

right = Regexp.new(<<REGEXP, Regexp::EXTENDED)
#{first}
match\\s # match
this    # match this
REGEXP

raise unless orig != wrong
raise unless orig == right

Files

regex_heredoc_patch (2.99 KB) regex_heredoc_patch patch to enable regex heredoc gam3 (Allen Morris), 08/24/2016 08:39 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0