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

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 (10)

  • 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
  • CNC Machining Parts Reply

    Fantastic article post. Much thanks again. Awesome.

    September 7, 2023 at 3:27 AM
  • bonito Reply

    I’m thankful for the article. Really looking forward to read more. Much obliged.

    October 11, 2023 at 10:23 AM
  • Sponaugle Reply

    I’m obliged for the blog post. Really thank you!

    October 26, 2023 at 10:38 AM
  • Kokubun Reply

    Thanks for the post. Much thanks again. Really Cool.

    October 28, 2023 at 12:22 PM
  • Nesseth Reply

    A big thank you for your blog. Much thanks again. Awesome.

    January 6, 2024 at 10:24 AM
  • Betancur Reply

    Thanks for sharing, this is a fantastic article post. Really Cool.

    January 22, 2024 at 8:47 AM

Leave a Reply

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