Use an explicit regular expression that matches (not- ) (not- ) , and add the replacement as $1 $2 (matching 1 to space 2). You may need to explicitly specify not- like ([^;]|[^p];|[^s]p;|[^b]sp;|[^n]bsp;|[^&]nbsp;) .
Change Although [negative] images can be useful (and, of course, less general code), you can measure the speed of each approach. I found that some mechanisms in regular expressions can be painfully slow compared to others, although I cannot speak directly with the speed of search queries. If speed becomes a problem, you can skip regular expressions and use a combination of strpos and substring operations and tests, which are often much faster than regular expressions, even if they are more cumbersome to create. I suggest this only because you have a very explicit string that you are looking for; with less defined lines, regex is definitely a way to go.
For this instance (in pseudo-code), finding the string strpos will be as simple as strpos($mystring, " ") , and as soon as you find a match, call strpos($mystring, " ") . If two calls to index return the same value, you can skip this replacement and do a row search after the indexed point (run your single search after indexDoubleFound + 12 , but run a double search after indexDoubleFound + 6 so you don't miss nobody, and you do not accidentally replace).
source share