3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pattern = '/^(\b\w+\b).*\b\1\b.*/i'; //should match $string = "TheseCharacters, I really enjoy TheseCharacters"; $result = preg_match($pattern, $string, $matches); echo "String 1 matches {$result} times: ".print_r($matches,true)."\n"; //should match $string = "TheseCharacters, I really enjoy TheseCharacters"; $result = preg_match($pattern, $string, $matches); echo "String 1 matches {$result} times: ".print_r($matches,true)."\n"; //match only with case insensitive flag, not an exact match in case $string = "TheseCharacters, I really enjoy TheseCharacters and some others"; $result = preg_match($pattern, $string, $matches); echo "String 2 matches {$result} times: ".print_r($matches,true)."\n"; //no match, TheseCharacters has been changed to TheseLetters $string = "TheseCharacters, I really enjoy TheseLetters"; $result = preg_match($pattern, $string, $matches); echo "String 3 matches {$result} times: ".print_r($matches,true)."\n"; //no match, additional letters has been added to TheseCharacters $string = "TheseCharacters, I really enjoy TheseCharactersasdf"; $result = preg_match($pattern, $string, $matches); echo "String 4 matches {$result} times: ".print_r($matches,true)."\n";
Output for 5.6.0 - 5.6.26, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
String 1 matches 1 times: Array ( [0] => TheseCharacters, I really enjoy TheseCharacters [1] => TheseCharacters ) String 1 matches 1 times: Array ( [0] => TheseCharacters, I really enjoy TheseCharacters [1] => TheseCharacters ) String 2 matches 1 times: Array ( [0] => TheseCharacters, I really enjoy TheseCharacters and some others [1] => TheseCharacters ) String 3 matches 0 times: Array ( ) String 4 matches 0 times: Array ( )

preferences:
232.5 ms | 404 KiB | 225 Q