I've got this regular expression which removes common words($commonWords
) from a string($input
) an I would like to tweak it so that it ignores hyphenated words as these sometimes contain common words.
return preg_replace('/b('.implode('|',$commonWords).')b/i','',$input);
thanks
Try
This adds negative lookaround expressions to the start and end of the regex so that a match is only allowed if there is no dash before or after the match.