in reply to Re: special regexp
in thread special regexp

Uhm, wasn't it you last time that told me about Death to Dot Star! last time? ;-)
I had [^x]*? where you are now using .*? - so why is .*? working here but [^x]*? not? *totallypuzzled*
--
Alfie

Replies are listed 'Best First'.
Re: Re: Re: special regexp
by danger (Priest) on Mar 26, 2001 at 12:30 UTC

    Yours is failing because you've anchored the match to where the previous one left off (with \G) and are also preventing moving across any 'x' characters that don't fit the x(.)(?=x) pattern by using the negative character class. The \G.*?x may traverse over an 'x' if the remainder of the expression fails.

    A simpler solution if you do not want to allow a "matched" 'x' to also count as a boundary 'x' is just:

    $_ = 'xaxbxcxdexfxxxx'; print $1 while /x(.)(?=x)/g; # abcfx

    If you do want to count 'matched' 'x' chars as potential boundary chars as well -- ie, 'xxxx' would produce 'xx' because there are two 'x' characters that have an 'x' on either side -- then:

    $_ = 'xaxbxcxdexfxxxx'; print $1 while /(?<=x)(.)(?=x)/g; # abcfxx