<br><font size=2><tt>spug-list-bounces@pm.org wrote on 2005-11-15 05:46:34
AM:<br>
<br>
> Ryan T. Kosai wrote:<br>
> > Here's an alternative regex that does what I think you might
actually want:<br>
> > <br>
> > #This one catches escaped # signs<br>
> > # Briefly, Capture anything other than a #, OR capture
a # if there's<br>
> > # a \ behind it<br>
> <br>
> Did you mean behind it like #\ or in front of it like \#?<br>
> <br>
> <br>
> > $line =~ /^(([^#]|(?:(?<=\\)[#]))*)/;<br>
> <br>
> It looks like you have one too many sets of capturing parentheses,
perhaps you<br>
> meant something like this:<br>
> <br>
> $line =~ /^((?:[^#]|(?<=\\)#)*)/;<br>
> <br>
> <br>
> And of course the question is moot if the OP is using this on perl
code as the<br>
> # character may not involve a comment, for example:<br>
> <br>
> my @array = qw# one two three #;<br>
> <br>
> my $string = sprintf '%#x %#x', 1234, 5678;<br>
> <br>
> <br>
> <br>
> John<br>
> -- <br>
> use Perl;<br>
> program<br>
> fulfillment<br>
> _____________________________________________________________<br>
> Seattle Perl Users Group Mailing List <br>
> POST TO: spug-list@pm.org<br>
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list<br>
> MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med<br>
> WEB PAGE: http://seattleperl.org/<br>
</tt></font>
<br><font size=2><tt>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.
</tt></font>
<br>
<br><font size=2><tt>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.</tt></font>
<br>
<br><font size=2><tt>$line =~ s/#.*//; # Now isn't this "simple"</tt></font>
<br>
<br>
<br><font size=2 face="sans-serif"><br>
---<br>
Rick Croote<br>
Software Engineer<br>
Environment and Tools Team<br>
Philips Medical Systems<br>
Bothell, WA<br>
Rick.Croote@Philips.com<br>
Phone: 425-487-7834<br>
</font>
<br>
<br>