in reply to Re: Re: special regexp
in thread special regexp
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
|
|---|