You can always simplify (?:(?:foo)) to (?:foo), even if there's something before or after it. Neither (?:) affects capture groups, and the inner (?:) is sufficient to make sure foo is treated as an atom for quantification purposes.
On Sun, Jan 25, 2009 at 7:46 PM, Avishalom Shalit <[email protected]> wrote: > but there's the "*" character. > > > 2009/1/25 Gaal Yahas <[email protected]>: >> You can always simplify (?:(?:foo)) to (?:foo). >> >> On Sun, Jan 25, 2009 at 7:13 PM, Shmuel Fomberg <[email protected]> wrote: >>> 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 >>>> [email protected] >>>> http://perl.org.il/mailman/listinfo/perl >>>> >>> >>> _______________________________________________ >>> Perl mailing list >>> [email protected] >>> http://perl.org.il/mailman/listinfo/perl >>> >> >> >> >> -- >> Gaal Yahas <[email protected]> >> http://gaal.livejournal.com/ >> _______________________________________________ >> Perl mailing list >> [email protected] >> http://perl.org.il/mailman/listinfo/perl >> > > > > -- > -- vish > _______________________________________________ > Perl mailing list > [email protected] > http://perl.org.il/mailman/listinfo/perl > -- Gaal Yahas <[email protected]> http://gaal.livejournal.com/ _______________________________________________ Perl mailing list [email protected] http://perl.org.il/mailman/listinfo/perl
