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

Re: TPR1 post-mortem

Thread Previous | Thread Next
From:
Philippe 'BooK' Bruhat
Date:
March 8, 2002 07:07
Subject:
Re: TPR1 post-mortem
Message ID:
1015600052.3c88d3b4995fb@imp3-1.free.fr
En réponse à "Keith C. Ivey" <kcivey@cpcug.org>:

> Marcelo E. Magallon <marcelo.magallon@bigfoot.com> 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.
> 
> I wondered that too.  I figured it was because \B wouldn't match 
> twice at the same place, but then I saw that s/\B./$&$&/g didn't work 
> as expected either.

What you want is:

    s/(?!^).(?!$)/$&$&/g

Now, can we shorten it?

    s/\B.(?=\B)/$&$&/g

Anything better?

-- 
 Philippe BRUHAT - BooK

 When you run from your problem, you make it that much harder for good
 fortune to catch you, as well.     (Moral from Groo The Wanderer #14 (Epic))

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About