develooper Front page | perl.fwp | Postings from March 2002

Re: TPR1 post-mortem

Thread Previous | Thread Next
Honza Pazdziora
March 8, 2002 06:27
Re: TPR1 post-mortem
Message ID:
On Fri, Mar 08, 2002 at 03:16:10PM +0100, Marcelo E. Magallon wrote:
>  A question of my own: why doesn't
>     s/\B.\B/$&$&/g
>  work as I expect, namely abcd -> abbccd.  I really can't figure it out
>  by reading the docs.

Because after matching the b and the non-boundaries around it, the
non-boundary between b and c already matched. So the next match for 
non-boundary will match between c and d, and since there is no \B
after d, you'll get abbcd.

You can try to rewrite the regexp as


and match


Here, it should be obvious that after matching _b_, your next chance
with _ is between c and d, not between b and c.


 Honza Pazdziora | |
      ... all of these signs saying sorry but we're closed ...

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About