everisk Posted June 2, 2009 Share Posted June 2, 2009 Hi, I have below code var c = '<p>Test [Name]</p> <p> [Time]</p> <p>[Link]</p> <p>List</p>'; c = c.replace(/>(\s+|\t)</, "><"); alert(c); It looks like replace only replace the first occurance of the RegEx match. Isn't it suppose to replace all? Can anyone please tell me how do I get it to replace all occurance of RegEx match? Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/160622-javascript-replace-function/ Share on other sites More sharing options...
bibby Posted June 2, 2009 Share Posted June 2, 2009 use the "greedy" flag on the expression c.replace(/>(\s+|\t)</g, "><"); added g to the end. Other flags are i , for case insensitive and m , that let's dot match newlines Link to comment https://forums.phpfreaks.com/topic/160622-javascript-replace-function/#findComment-847820 Share on other sites More sharing options...
Ken2k7 Posted June 2, 2009 Share Posted June 2, 2009 IIRC, g stands for global, not greedy. Am I wrong? Link to comment https://forums.phpfreaks.com/topic/160622-javascript-replace-function/#findComment-847938 Share on other sites More sharing options...
bibby Posted June 3, 2009 Share Posted June 3, 2009 That's correct, Ken2k7. "greedy" is pattern matching itself. my bad Link to comment https://forums.phpfreaks.com/topic/160622-javascript-replace-function/#findComment-848587 Share on other sites More sharing options...
everisk Posted June 4, 2009 Author Share Posted June 4, 2009 Thank you! bibby and Ken2k7. Got it working now. Link to comment https://forums.phpfreaks.com/topic/160622-javascript-replace-function/#findComment-849028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.