SPUG: regular expression question
rick.croote at philips.com
Fri Nov 18 10:57:10 PST 2005
spug-list-bounces at pm.org wrote on 2005-11-15 05:46:34 AM:
> Ryan T. Kosai wrote:
> > Here's an alternative regex that does what I think you might actually
> > #This one catches escaped # signs
> > # Briefly, Capture anything other than a #, OR capture a # if there's
> > # a \ behind it
> Did you mean behind it like #\ or in front of it like \#?
> > $line =~ /^(([^#]|(?:(?<=\\)[#]))*)/;
> It looks like you have one too many sets of capturing parentheses,
> meant something like this:
> $line =~ /^((?:[^#]|(?<=\\)#)*)/;
> And of course the question is moot if the OP is using this on perl code
> # character may not involve a comment, for example:
> my @array = qw# one two three #;
> my $string = sprintf '%#x %#x', 1234, 5678;
> use Perl;
> 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 Pac-Med
> WEB PAGE: http://seattleperl.org/
Great point John. I've done this type of project, like most of us I'm
sure, and always found myself analyzing on a char at a time basis, because
you need to know if you are in a comment, multi-line comment, quoted
string and who knows what else you will run into. I found that line at a
time parsing was too difficult for this type of project.
But in the interest of fun, if I were not concerned about embedded comment
characters and just wanted to eliminate them line by line, I always prefer
the trimming style, rather than the capture.
$line =~ s/#.*//; # Now isn't this "simple"
Environment and Tools Team
Philips Medical Systems
Rick.Croote at Philips.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the spug-list