Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Seaching for Words at the beginning of the line and end of line

How do I search for the word "intern" without searching for "internal"?



What I have been doing is /intern[^a]/ but that won't match /intern$/.



Thanks,

Siegfried





Report this thread to moderator Post Follow-up to this message
Old Post
Siegfried Heintze
06-03-05 08:56 AM


Re: Seaching for Words at the beginning of the line and end of line
On Jun 2, Siegfried Heintze said:

> How do I search for the word "intern" without searching for "internal"?
>
> What I have been doing is /intern[^a]/ but that won't match /intern$/.

You want to use a negative look-ahead:

/intern(?!al)/

That means "match 'intern' that is not followed by 'al'".  But perhaps you
just want to use word boundaries?

/\bintern\b/

That will only match "intern" when there are no word characters to the
left or right of it.  Thus, "I am an intern" will match, but "internal
problems" and "abintern" won't match.  ("Abintern" isn't a word, but I
wanted to prove a point.)

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

Report this thread to moderator Post Follow-up to this message
Old Post
Jeff 'japhy' Pinyan
06-03-05 08:56 AM


RE: Seaching for Words at the beginning of the line and end of line
Thanks! Yes I want the \b.

Now what about this:

s/\bJr\b/ Junior /gi;

This is not exactly what I want because it will put a space before "Junior"
even if Junior is at the beginning and I don't want a space?

I suppose I could do this:

s/(\b)Jr(\b)/\1Junior\2/gi;

Is there an easier way?

Thanks,
Siegfried

-----Original Message-----
From: Jeff 'japhy' Pinyan [mailto:japhy@perlmonk.org]
Sent: Thursday, June 02, 2005 7:04 PM
To: Siegfried Heintze
Cc: beginners@perl.org
Subject: Re: Seaching for Words at the beginning of the line and end of line

On Jun 2, Siegfried Heintze said:

> How do I search for the word "intern" without searching for "internal"?
>
> What I have been doing is /intern[^a]/ but that won't match /intern$/.

You want to use a negative look-ahead:

/intern(?!al)/

That means "match 'intern' that is not followed by 'al'".  But perhaps you
just want to use word boundaries?

/\bintern\b/

That will only match "intern" when there are no word characters to the
left or right of it.  Thus, "I am an intern" will match, but "internal
problems" and "abintern" won't match.  ("Abintern" isn't a word, but I
wanted to prove a point.)

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart


Report this thread to moderator Post Follow-up to this message
Old Post
Siegfried Heintze
06-03-05 08:56 AM


RE: Seaching for Words at the beginning of the line and end of line
On Jun 2, Siegfried Heintze said:

> s/\bJr\b/ Junior /gi;
>
> This is not exactly what I want because it will put a space before "Junior
"
> even if Junior is at the beginning and I don't want a space?

Just do

s/\bJr\b/Junior/gi;

The \b is an anchor -- it matches a location, not a character.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

Report this thread to moderator Post Follow-up to this message
Old Post
Jeff 'japhy' Pinyan
06-03-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:47 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.