I am trying to write a regex to recognize a single line of text, with underscore ( _ ) recognized as a line continuation character. For example, "foo_\nbar" should be considered a single line, because the "foo" ends in an underscore. I am trying:
$txt = "foo_\nbar";
print "$&\n" if $txt =~ /.*(_\n.*)*/;
However, this prints only:
foo_
This seems to violate the "leftmost longest" rule for Perl regexes!
Interestingly, if I remove the last star (*) in the regex, i.e.:
$txt = "foo_\nbar";
print "$&\n" if $txt =~ /.*(_\n.*)/;
it does print:
foo_
bar
But I need the star to recognize "0 or more" continuations!
What am I doing wrong?