Suppose you want to match text that is delimited by double characters like so:
a = <<
Hello
World!
>>
The regular expression /<<(.*)>>/ would seem to do it, but unfortunately when these can be repeated greedy matching gets too much:
a = <<
Hello
World!
>>
b = <<
Goodbye
World!
>>
The previous regexp will capture
Hello
World!
>>
b = <<
Goodbye
World!
The obvious answer is to make the regexp non-greedy: /<<(.*?)>>/
Unfortunately this has extreme performance problems for long strings (in Perl at least). If the delimiters were single characters, then we could use a character class (everything but the character) to solve the greedy problem.
Any ideas on a regular expression to make this match without the performance penalty?
NB: I have to use Perl and this has to be a regular expression because of the larger system it's embedded in.
Thanks.