Firstly, I hate to be a pain but I'd like to know how to specifically do this in the Search Regex WordPress plugin. It's a popular plugin, but I don't understand how the Replace pattern works for it, it suggests that it accepts regex, but ends up just using literals.
How can I use a replace pattern to insert a space after a certain set of letters. I have the search pattern sorted, just need to know how to replace with a space.
So if we supposed I had a search that looked for every instance where 'testing' was followed by a few letters and I wanted to put a space after each instance.
should be replaced with...
preguntado el 09 de marzo de 12 a las 14:03
\b at the start and a negative lookahead for your match:
preg_replace('#(\btesting)(?!\s)#', '$1 ', $origString);
preg_replace('/('.preg_quote($sSearch, '/').')(?! )/', '$1 ', $sSubject);
OK, I know my initial question is probably not very clear, but just in case this helps anyone in future, what I eventually realised is that I needed to split up my Regex search term using brackets e.g.
If I wanted to split up some words, where 'testing' was followed by a bunch of other letters than I would search for...
Then the replace pattern would be...
the \1 would match the search pattern in the first set of brackets, then I have a space, and the \2 would match the search pattern in the second set of brackets. So let's take the following string...
foo testingbar 123
Under the search and replace patterns above, the string would be replaced by...
foo testing bar 123