SPUG: regular expression question
John W. Krahn
krahnj at telus.net
Mon Nov 14 22:41:03 PST 2005
Charles Connolly wrote:
> I'm having some trouble with a regular expression, and I thought I'd toss
> it out to the list, especially since it seems quiet here lately.
> I'd like to process a file line by line, capturing the everything from the
> start of the line to a hash mark (#), which would indicate a comment. Here are
> some things I tried:
> my $line =~ /^(.*)\#?/; # this takes the entire line, as expected.
> my $line =~ /^(.*?)\#?/; # this works if there is a comment, but not if there
> isn't. If there isn't a comment it captures the shortest match, which is
> All suggestions are welcomed.
my $line =~ /^([^#]*)/;
More information about the spug-list