Is it possible to combine multiple heredoc expressions with regular expressions?

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 .

+7
regex
source share

No one has answered this question yet.

See similar questions:

1323
RegEx match open tags, with the exception of XHTML tags
0
How to add \ n after every third match in regular expression?

or similar:

3892
Regular expression to match a wordless string
3175
How to check email address with regex?
1323
RegEx match open tags, with the exception of XHTML tags
1251
How to access mapped groups in JavaScript regex?
1215
How do you use a variable in a regular expression?
950
Is there a regular expression to determine the correct regular expression?
839
Full regex to verify phone number
591
Check string match regex in js
491
Match all regexp appearances
3
Regular Expressions (pcre) for shortcode / bbcode

All Articles