<?php

$string = <<<DATA
<p>{{ myFunction()&nbsp; }}</p>    
<p>&nbsp;</p>    
<p>{{ number|number_format(2, "&nbsp;.&nbsp;", '&nbsp;,&nbsp;')&nbsp;}}</p>    
<p>{% set myVariable = '&nbsp;&nbsp;' %}</p>
DATA;

$regex = '~
			(?:(?:\{{2}|\{%)
			|
			\G(?!\A))
			(?:(?!(?:\}{2}|%\})).)*?\K
			&nbsp;
		  ~x';
$string = preg_replace($regex, ' ', $string);
echo $string;
?>