stuckwithcode Posted January 13, 2010 Share Posted January 13, 2010 Hello, The code below alows me to replace the sequence ", , " with just one ", " (comma then a space) text = text.replace(/[,]\s[,]\s/gm,", "); How can I amend the code so that however many I have in a row eg . ", , , , , " or ", , , " all get changed to one ", " Thanks. Quote Link to comment Share on other sites More sharing options...
salathe Posted January 13, 2010 Share Posted January 13, 2010 Try, text = text.replace(/(?:, ){2,}/g, ', '); Terms to research are "non-capturing group" and "quantifiers" Quote Link to comment Share on other sites More sharing options...
stuckwithcode Posted January 13, 2010 Author Share Posted January 13, 2010 Thanks for the help. 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.