3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$input = "I don't want this piece. This is the sentence I want. In don't want this piece either"; $input = "I don't want this piece! This is the <a href='https://example.com/my-sentence'>sentence</a> I want. In don't want this piece either"; $filter = "sentence"; $regex = '~\b(?:[^.?!]|https?://[^<>\s"\']++)*?'.preg_quote($filter, '~').'(?:[^.?!]|https?://[^<>\s"\']++)*~u'; if (preg_match_all($regex, $input, $match)){ print_r( array_map(function($x) {return strip_tags($x);}, $match[0]) ); }

preferences:
29.84 ms | 402 KiB | 5 Q