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