PHP Regex: Remove words not equal exactly 3 characters

  php, preg-replace, regex

An excellent "very close" answer at
Remove words less than 3 chars
with DEMO
where Regex

b([a-z]{1,2})b

removes all words less than 3 chars.

But how to reset this demo vise versa ? to remove all words NOT EXACTLY EQUAL 3 chars ?
We can catch word where exactly 3 chars by

b([a-z]{3})b

but how to tell regex – remove all other words what are NOT equal to 3 ?

So in regex demo ref above should leave only word ‘and’

Source: Ask PHP

LEAVE A COMMENT