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

后端 未结 8 1172
天涯浪人
天涯浪人 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

    Assuming the words in your list may be letters from a to z and you allow, but do not require, a space after the comma separators, your reg exp would be [a-z]+(,\s*[a-z]+)*

    This is match "ab" or "ab, de", but not "ab ,dc"

提交回复
热议问题