Matching double words
Posted: Fri Aug 06, 2010 1:55 am
I am trying to match every single adjacent two words (not separated by punctuation).
Here is my code:
The results were:
array(1) { [0]=> array(5) { [0]=> string(7) "How are" [1]=> string(9) "you doing" [2]=> string(4) "I am" [3]=> string(10) "doing fine" [4]=> string(9) "why thank" } }
I don't understand why "are you" and "you doing" do not match.
How would I fix the regex?
Here is my code:
Code: Select all
$sentence = "How are you doing today? I am doing fine, why thank you.";
preg_match_all('#[a-z]+\s[a-z]+#i', $sentence, $doubleWordArray);
var_dump($doubleWordArray);array(1) { [0]=> array(5) { [0]=> string(7) "How are" [1]=> string(9) "you doing" [2]=> string(4) "I am" [3]=> string(10) "doing fine" [4]=> string(9) "why thank" } }
I don't understand why "are you" and "you doing" do not match.
How would I fix the regex?