[Israel.pm] Regex question

Shmuel Fomberg semuelf at 012.net.il
Sun Jan 25 09:13:04 PST 2009


Thanks for the answer.

What about the:
		(?:
			# Allow both :: and ' in namespace separators
			(?: \' (?!\d) \w+ | \:: \w+ )
		)*

does the double parenthesis do something, or can it be collapsed to:

		# Allow both :: and ' in namespace separators
		(?: \' (?!\d) \w+ | \:: \w+ )*

?

Shmuel.



Yitzchak Scott-Thoennes wrote:
> 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
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
> 




More information about the Perl mailing list