简体   繁体   中英

Regex to match two or more comma separated integers

I have a list of comma separated values:

123            should fail   // using my regex this pass 
123, 230       should pass
234, 560, 890  should pass

using this regex ^(\d+(, \d+)*)?$ if it is a single value, it still passes.

How can I only match 2 or more integers in the list?

Change the * to a + . * means 0 or more matches, + means 1 or more.

You should use the + instead of * to make sure teh (, \d+) part exists at least 1 time.

^(\d+(, \d+)+)?

Check this:
https://regex101.com/r/yvWiZ0/1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM