Regular expression for a list of items separated by comma or by comma and a space

后端 未结 8 1177
天涯浪人
天涯浪人 2020-12-15 05:02

Hey, I can\'t figure out how to write a regular expression for my website, I would like to let the user input a list of items (tags) separated by comma or by comma and a spa

8条回答
  •  暖寄归人
    2020-12-15 05:32

    This thread is almost 7 years old and was last active 5 months ago, but I wanted to achieve the same results as OP and after reading this thread, came across a nifty solution that seems to work well

    .match(/[^,\s?]+/g)
    

    Here's an image with some example code of how I'm using it and how it's working

    Regarding the regular expression... I suppose a more accurate statement would be to say "target anything that IS NOT a comma followed by any (optional) amount of white space" ?

提交回复
热议问题