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

Popular posts from this blog

delphi - TJvHidDeviceController "DevicePath" always showing "\" -

Disabling Android home button for industry application -

asp.net mvc 3 - Unexpected "foreach" keyword after "@" character -