Dustin013 Posted August 6, 2009 Share Posted August 6, 2009 $re1='(Address)'; # Word 1 $re2='.*?'; # Non-greedy match on filler $re3='(Request)'; # Word 2 if ($c=preg_match_all ("/".$re1.$re2.$re3."/is", $txt, $matches)) { $word1=$matches[1][0]; $word2=$matches[2][0]; print "($word1) ($word2) \n"; } The above will output (Address) (Request). What do I do if I want to grab the filler in between those two words? Link to comment https://forums.phpfreaks.com/topic/169118-how-would-you-regex/ Share on other sites More sharing options...
thebadbad Posted August 6, 2009 Share Posted August 6, 2009 If you enclose .*? in parentheses, $matches[2][0] will hold the filler and $matches[3][0] the second word. Link to comment https://forums.phpfreaks.com/topic/169118-how-would-you-regex/#findComment-892463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.