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! Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. 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.