I'm doing some SEO of huge catalog product descriptions using preg_replace_callback and have some difficulties with regex.
I'd like to replace all these words (hat, shirt) except ones after "men's" + 0-2 words between, e.g. "men's pretty black hat", "men's long shirt" shouldn't be replaced.
Here is a debug code, in real application I use callback to pick proper replacement for each word:
$str = "men's black hat, and orange shirt!";
preg_match_all('/((\s|\.\s|,\s|\!\s|\?\s)(hat|shirt)(\s|\.|\.\s|,\s|\!|\!\s|\?|\?\s))/i', $str, &$_matches);
print_r($_matches);
Thanks