Is there any regex mechanism that would allow me to match multiple heredoc lines in an expression? For example, how one could write in Ruby:
f <<FOO, 10, <<BAR, 20 some text FOO some more text BAR
It's hard for me to use backrefs and recursive call in Perl flavor, but failed to execute cross-sequential dependencies (i.e., failed to cancel the captured backrefs, since FOO must match before the BAR ). I also thought about balancing groups on .Net, where I can cancel the stack using lookaheads (I know this is a terrible hack), for example:
(?:(?<x>foo|bar|baz)|\s)+(?(x)|(?!))\s*(?(x)(?=(.*?)(?<-x>(?<y>\k<x>)))){3}(?(x)(?!))(?:(?(y)(?<-y>\k<y>))|\s)+(?(x)(?!))(?(y)(?!))
(Click here to check it out.)
This corresponds to foo bar baz foo bar baz , but then I have to add a manual counter ( {3} ) since lookahead will not repeat with + , since it does not consume any input that I assume. Thus, this will not work in arbitrary cases (but it was close!). I could, of course, replace this with {1000} or any other large number, and that will answer my question, but I wonder if there are other ways.
Confirmation I understand that it would be nice to match such a construction with regular expressions. I am engaged in research on such, and I want to find out if this is possible. If so, please do not use it in production code .
regex
paulotorrens
source share