Regular expression in PHP for finding whole words

I want a code in PHP with regular expressions that returns whole words for any matches. For example if search for ac I want it returns all words in a string that have ac in any part. i.e. if the String have facebook or act or face it returns all the words to me, I wrote this code but does not work properly.

$regx = "/b(S)*ac(S)*/iu"; 
    foreach($values as $value) 
    {
        echo $value."n";
        preg_match_all($regx, $value, $matches,PREG_PATTERN_ORDER);
        var_dump($matches);
    }


Source: regex

Leave a Reply