On Sat, January 24, 2009 4:40 pm, Shmuel Fomberg wrote:
> Is it correct that this regex:
>
> $content =~ /^(
> [...@%&*]
> (?: : (?!:) | # Allow single-colon non-magic vars
> (?: \w+ | \' (?!\d) \w+ | \:: \w+ )
> (?:
> # Allow both :: and ' in namespace separators
> (?: \' (?!\d) \w+ | \:: \w+ )
> )*
> (?: :: )? # Technically a compiler-magic hash, but keep
> #it here
> )
> )/x;
>
> is the same is this?
>
> $content =~ /^(
> [...@%&*]
> (?: : (?!:) | # Allow single-colon non-magic vars
> (?: \w+ | \' (?!\d) \w+ | \:: \w+ )
> )
> # Allow both :: and ' in namespace separators
> (?: \' (?!\d) \w+ | \:: \w+ )*
> (?: :: )? # Technically a compiler-magic hash, but keep it here
> )/x;
No, the second one continues on after a single colon to look for a namespace
separator, etc, where the first one would have stopped. So when $content
is "$:'a", one matches two characters and one matches all four.
To show the difference more simply, you are asking if
( A (?: B | C D ) )
is the same as
( A (?: B | C ) D )
Moving D makes it matched after B or C instead of just after C.
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl