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. Link to comment https://forums.phpfreaks.com/topic/188348-help-with-replace/ 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" Link to comment https://forums.phpfreaks.com/topic/188348-help-with-replace/#findComment-994317 Share on other sites More sharing options...
stuckwithcode Posted January 13, 2010 Author Share Posted January 13, 2010 Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/188348-help-with-replace/#findComment-994341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.