JavaScript regular expression to match a comma delimited list

JavaScript regular expression to match a comma delimited list

This method uses the JavaScript String’s match() method to parse a comma delimited list and show its content in a Panel control.

You can try it here http://jsfiddle.net/38tXU/

function parseList(list) {
    var reg = list.match(/\w+(,\w+)*/g);
    document.getElementById('pnl').innerHTML = 'Total length:' + reg.length + '<br />';
    for (var i = 0; i < reg.length; i++) {
        document.getElementById('pnl').innerHTML += 'Token:\'' + reg[i] + '\'<br />';
    }
}
//Call parseList function
parseList('item1, item2, item3');

Share this post

Comments (4)

  • Orval Keith Reply

    This is my first time visit at here and I am actually happy to read everything at single place. Thank you!

    October 24, 2010 at 2:44 AM
  • Nigel Sandoval Reply

    I am now not positive the place you are getting your info, however great topic. I must spend a while studying much more or understanding more. Thanks for magnificent info I used to be on the lookout for this information for my mission.

    February 23, 2011 at 5:26 PM
  • Victor Zhang Reply

    Article writing is also a fun, if you know then you can write if not it is complex to write.

    November 25, 2015 at 5:48 AM
  • Kate Curtis Reply

    Hello! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I’m getting sick and tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform. I would be great if you could point me in the direction of a good platform.

    February 25, 2022 at 5:29 PM

Leave a Reply

Your email address will not be published. Required fields are marked *