3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $search = preg_quote('test'); $extra_words = 3; $pattern = '#([^ ]+ ){0,'.$extra_words.'}'.$search.'( [^ ]+){0,'.$extra_words.'}#'; $res = preg_match_all($pattern,'some more text write your test data found more than once test here ',$regs); var_dump($regs);
based on QltdJ
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> array(2) { [0]=> string(36) "text write your test data found more" [1]=> string(19) "than once test here" } [1]=> array(2) { [0]=> string(5) "your " [1]=> string(5) "once " } [2]=> array(2) { [0]=> string(5) " more" [1]=> string(5) " here" } }