jaymc Posted November 1, 2007 Share Posted November 1, 2007 I am using replace() to replace some text, the issue I have is after it finds the first occurance of my needle it ignores the rest of the haystack text = 'y did the cow jump over the mean can you tell me y or tell me y you can tell me' text = text.replace('y', 'why') For some reason, its only replacing the first y, it ignores the other 2. Any ideas why/way around it Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 try this text = text.replace(/y/g, 'why') Quote Link to comment Share on other sites More sharing options...
jaymc Posted November 1, 2007 Author Share Posted November 1, 2007 Thats pretty cool, but I have a new problem as a result of that chat.replace(/:(/g It does like the ( which is part of How can I get around this without changing the to :sad: or something Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 1, 2007 Share Posted November 1, 2007 I think this should work just escape the ( chat.replace(/:\(/g Quote Link to comment Share on other sites More sharing options...
jaymc Posted November 1, 2007 Author Share Posted November 1, 2007 Oh yes how stupid of me! Cheers for help. All done Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.