Re: Another regexp conundrum
Ronald J Kimball <[email protected]>
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Jun 01, 2004 at 02:11:56PM -0400, [email protected] wrote: > 13 '__pqr____xyz__pqr___abc___' =~ /(($re).*?)*(?!)/; > Of course, this is incomplete, but it is a start. One thing that > puzzles me is that the (?!) is absolutely required on line 13. > Without it, @seen doesn't get initialized at all. Why should this be? > I would have thought that the final '*' in the regexp would be enough > to get the regexp to continue attempting to match. /(anything)*/ can always match a zero length substring at the beginning of the string, and as soon as the regex engine finds a match, it stops. The (?!) forces the regex engine to backtrack through all possible matches. Ronald