Finding two words with Regular Expression

how do I find two words anywhere in a string

Page 1 of 1

1 Replies - 3656 Views - Last Post: 02 February 2009 - 09:20 PM

#1 xesecre   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 29-July 08

Finding two words with Regular Expression

Posted 02 February 2009 - 08:27 PM

Hello,
I am looking to put together a regular expression to find two words in a string

example would be if I was using a foreach statements to loop through a header one word at time between tabs

if I have City********}state*********zip}

foreach $word (@array)

{
if ($word =~ m/\bcity\w+\bstate/gi)
{ print OUT "add3";}

}


this is what I have done so far
I was trying to use the \b boundaries
I want it to find those two words between spaces or whatever just so it finds those two words or even part of those two words

I have been studying regex's but I still cannot figure this one out and I did some research for a while before even bothering to ask this question
thanks for your time
John

This post has been edited by xesecre: 02 February 2009 - 08:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Finding two words with Regular Expression

#2 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Finding two words with Regular Expression

Posted 02 February 2009 - 09:20 PM

Post some real data and try and explain what you are doing more precisely.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1