fork download
  1. <?php
  2.  
  3. $text1 = "i did";
  4. preg_match("~(did|\w+(?= did)) (did|(?<=did )\w+)~", $text1, $match1);
  5. print_r($match1);
  6.  
  7. $text2 = "did i";
  8. preg_match("~(did|\w+(?= did)) (did|(?<=did )\w+)~", $text2, $match2);
  9. print_r($match2);
  10.  
  11. $text3 = "did x, x did";
  12. preg_match_all("~(did|\w+(?= did)) (did|(?<=did )\w+)~", $text3, $match3);
  13. print_r($match3);
  14.  
  15. $text4 = "a a";
  16. preg_match("~(did|\w+(?= did)) (did|(?<=did )\w+)~", $text4, $match4);
  17. print_r($match4);
  18. ?>
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => i did
    [1] => i
    [2] => did
)
Array
(
    [0] => did i
    [1] => did
    [2] => i
)
Array
(
    [0] => Array
        (
            [0] => did x
            [1] => x did
        )

    [1] => Array
        (
            [0] => did
            [1] => x
        )

    [2] => Array
        (
            [0] => x
            [1] => did
        )

)
Array
(
)