Page 1 of 1

Want to pull the data between two words

Posted: Fri May 22, 2009 11:44 am
by smacky311
I have the following pattern:

Code: Select all

 
 $regexp = "/Country: .* City: /";
        if (preg_match($regexp, "Country: United States (XX) City: (Unknown City?) ", $matches)) {
          echo "Match was found <br />";
          echo $matches[0];
        }
 
It returns "Country: United States (XX) City: ". I only want the regular expression to return: "United States (XX)". How can this be done?

Re: Want to pull the data between two words

Posted: Fri May 22, 2009 12:41 pm
by prometheuzz
Try:

Code: Select all

'/(?<=country:).*?(?=city)/is'