SPUG: regular expression question
John W. Krahn
krahnj at telus.net
Tue Nov 15 05:46:34 PST 2005
Ryan T. Kosai wrote:
> Here's an alternative regex that does what I think you might actually want:
>
> #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, perhaps you
meant something like this:
$line =~ /^((?:[^#]|(?<=\\)#)*)/;
And of course the question is moot if the OP is using this on perl code as the
# character may not involve a comment, for example:
my @array = qw# one two three #;
my $string = sprintf '%#x %#x', 1234, 5678;
John
--
use Perl;
program
fulfillment
More information about the spug-list
mailing list