Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Mar 2002 14:04:44 +0000
From:      Daniel Bye <dan@slightlystrange.org>
To:        freebsd-questions@freebsd.org
Subject:   Re: perl question
Message-ID:  <20020319140444.A2230@icarus.slightlystrange.org>
In-Reply-To: <20020318200222.A6691@lastamericanempire.com>; from cublai@lastamericanempire.com on Mon, Mar 18, 2002 at 08:02:22PM -0700
References:  <001c01c1cee9$54b626d0$d4e18aca@melsa.net.id> <20020318200222.A6691@lastamericanempire.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Mar 18, 2002 at 08:02:22PM -0700, Zach Thompson wrote:
> * ekoz <ekoz@melsa.net.id> [020318 19:07]:
> > Hi All,
> > 
> > I have a little problem with perl. I try to delete a few line in a file with perl. I have a following line :
> > 
> > cs
> > cs.tpkkoja
> > 
> > I use "s/\bcs\b/ /;" to deleting the word "cs" and i don't want to deleting  "cs.tpkkoja" but, i get this result :
> > 
> >      .tpkkoja
> > all the word "cs" is deleted include in "cs.tpkkoja".
> > Any Suggestions ?
> 
> If the "cs" you want to delete is always on a line of itself:
> 
> s/^cs$//;
> 
> You could add other things like checking for leading/trailing whitespace
> too.

You could also try using one of the lookahead assertion forms:

s/cs(?![.A-Za-z]+)//;

This will match /cs/ when NOT followed by, in this case, any letter or a
period.  You will need to alter the regexp in the assertion to suit your own 
needs (the bit inside the (?!...) token)
  

> 
> Zach Thompson
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message

HTH

Dan

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020319140444.A2230>