Search code examples
javascripttitaniumtitanium-mobileampersand

string.replace for Titanium webview


I have tried the following to no avail

var clean = link.replace(/\&nbsp\; /gi,' ');

I have also tried without escaping both the & and ; and escaping only one but it doesn't work. I can replace just plain nbsp. Is there any way to replace   with just ' '?


Solution

  • I've been working on this with some people over on the Appcelerator Q&A and the best answer I could come up with is a work around at best.

    var clean = link.replace(/nbsp/g," ").replace(/\&/g,"").replace(/amp\;/g,"").replace(/\;/g,"");
    

    For obvious reasons this won't work for everybody since it will wipe out all semicolons and ampersands but it worked for me. I'm perplexed as to why I can't get the entire   replaced but for now I'm happy.