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 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -