php - Regexp to ignore hyphenated words during common word removal pattern -
i've got regular expression removes common words($commonwords
) string($input
) tweak ignores hyphenated words these contain common words.
return preg_replace('/\b('.implode('|',$commonwords).')\b/i','',$input);
thanks
try
return preg_replace('/(?<!-)\b('.implode('|',$commonwords).')\b(?!-)/i','',$input);
this adds negative lookaround expressions start , end of regex match allowed if there no dash before or after match.
Comments
Post a Comment