SPUG: regular expression question

Ben Prew ben.prew at gmail.com
Wed Nov 16 23:01:28 PST 2005


The idea of using the "not character class" is well spelled out in Curtis'
(Ovid) post on perlmonks (http://perlmonks.org/?node_id=24640).

If you've not read it, I highly recommend it, and perlmonks for that matter.

On 11/14/05, John W. Krahn <krahnj at telus.net> wrote:
>
> Charles Connolly wrote:
> > Hi,
> > 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
> > nothing.
> >
> > All suggestions are welcomed.
>
> my $line =~ /^([^#]*)/;
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location: Amazon.com <http://Amazon.com> Pac-Med
> WEB PAGE: http://seattleperl.org/
>



--
Ben Prew
ben.prew at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20051117/686f174c/attachment.html


More information about the spug-list mailing list