----- Original Message -----
From: "David Draley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 24, 2001 8:13 AM
Subject: reg exp match


> How would I print only the words that contain the letter "p" in a file???
> Right now I am only printing the entire lines that contain words with the
> letter "p".
>
> while (<FILE>)
>                 {
>                   if(/[p]/)
>                         {
>                          print "$_";
>                         }
>                 }
> close(FILE);
>
>
> thanks in advance
>


You could try a regex like this:
/\b\w*?p\w*?\b/

which translates as:
[word boundary] [any number (but not too many) of letters] [somewhere in
there a 'p'] [any number of letters] [another word boundary]

That would take care of most your needs, if you need to match contractions,
you could substitute \w with [\w'].

Also, tack on an 'i' at the end if you also want to look for words that have
a capital P in them.

-jarrod.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to