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 Link to comment https://forums.phpfreaks.com/topic/75641-solved-replace/ 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') Link to comment https://forums.phpfreaks.com/topic/75641-solved-replace/#findComment-382742 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 Link to comment https://forums.phpfreaks.com/topic/75641-solved-replace/#findComment-382788 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 Link to comment https://forums.phpfreaks.com/topic/75641-solved-replace/#findComment-382790 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 Link to comment https://forums.phpfreaks.com/topic/75641-solved-replace/#findComment-382795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.