Have you tried to escape the spaces? For example `term = " mystring " then should return "\ mystring\ ".

I'm a little worried if removing the spaces could cause colateral problems...