警告:preg_match()[function.preg-match]:编译失败:在偏移22处不重复

i'm trying to change the preg_match check from url checking and i'm getting this error

Blockquote preg_match_all(): Compilation failed: nothing to repeat at offset 22

this is the code:

preg_match_all('#\b(' . $allWordsFromProduct . ')\b#ui', $name, $matches);

May $allWordsFromProduct contains special regex character. You can try:

 $allWordsFromProduct = preg_quote($allWordsFromProduct , '#');
 preg_match_all('#\b(' . $allWordsFromProduct . ')\b#ui', $name, $matches);

This will escape them.