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

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

java - where to store the user credentials in an enterprise application(EAI)? -

openxml - Programmatically format a date in an excel sheet using Office Open Xml SDK -