Help witjh Preg_Match_All with Regex

Hi guys,

Being plagued with annoying spam over the last few weeks on my forums and looking to build a quick function to detect strings that look like this:

Watch () Online
Stream (
) Online

So if the post string = $post_text - are there any code examples as to how I could use preg_match_all to detect it - if $post_text contains at least one instance of the above, then do this.

Many thanks,
Jorge

Not tested

<?php
preg_match_all('#[watch,stream](.+)online#', strtolower($str), $match);
var_dump( $match );
?>

The square bracket group means any character within the bracket selection so you are basically eliminating any words containing those letters and a comma!

This should work better and preg_match (without all) should be suffictient:


$match_exists = preg_match('#(watch|stream).+?online#i', $str);

This will match these strings:

buy watch online now!
watch online
Watches online
WATCH-ONLINE
WATCH any text here provided it’s in one line(!) ONLINE
Stream online
best streaming online

If you want to also catch cases when the two words are in different lines then add the ‘s’ modifier to the end of the regex.

Ouch! I messed up the parentheses types (must confess I’m not a regExp expert).