From: shyouhei@... Date: 2017-11-24T00:53:21+00:00 Subject: [ruby-core:83873] [Ruby trunk Feature#12700] regexg heredoc support Issue #12700 has been updated by shyouhei (Shyouhei Urabe). duerst (Martin D��rst) wrote: > > So I changed my mind. Let me +1. > > If that 300+ lines regexp is public (or can be made public), I'd like to see a pointer. Here you are: https://github.com/shyouhei/optdown/blob/master/lib/optdown/expr.rb > There may be exceptions, but I don't think it's a good idea to write a regexp constant with 300+ lines by hand. > (The regular expression pieces in https://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/unicode_normalize/tables.rb?view=markup are way shorter than 300 lines, but I wouldn't have wanted to write them by hand anyway.) I have to agree with this part from the bottom of my heart. It was a wrong decision for me to write the expression above. I should have used something different. But I did it anyway because it seemed possible. And it was. The experience was terrible as expected. A regexp heredoc should absorb some part of the pain I believe. > Looking at the examples above, the advantages for the regexp heredoc over %r seem to be the fact that two or more of them can be started in the same line (including the options). The advantage over indirect construction via string heredoc seems to be that no double escape is necessary. None of these advantages seems directly related to the length of the regexp. True. What I found during writing a long regular expression is that the expression seemed to contain all the possible punctuation character to be used in %r. Two or more characters to terminate the expression seemed the right solution. At the same time I needed to interporate variables into the expression I could not use `Regexp.new(< Just some points; I'm not too strongly against introducing this. We can live without heredoc regexps. In fact I do in the example above. However, that is also true for all other sort of heredocs; we don't need them in theory if we could properly escape everything. In practice that is too annoying. The same goes with regexp literals I believe. ---------------------------------------- Feature #12700: regexg heredoc support https://bugs.ruby-lang.org/issues/12700#change-67909 * Author: gam3 (Allen Morris) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- There is support for ', ", and ` heredocs, but there is no support for /. Example code with new feature: ~~~ ruby first = 'first' orig = /#{first} match\s # match this # match this /x right = <