I am trying to write a regular expression to recognize a single line of text, with the underscore (_) being recognized as a line continuation character. For example, "foo_ \ nbar" should be considered as one line, because "foo" ends with an underscore. I'm trying to:
$txt = "foo_\nbar";
print "$&\n" if $txt =~ /.*(_\n.*)*/;
However, this only prints:
foo_
This seems to violate the longest rule for Perl regular expressions!
Interestingly, if I remove the last star (*) in the regular expression, that is:
$txt = "foo_\nbar";
print "$&\n" if $txt =~ /.*(_\n.*)/;
he performs printing:
foo_
bar
But I need a star to find out "0 or more" sequels!
What am I doing wrong?
source
share