Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for Comma delimited list

Tags:

regex

csv

What is the regular expression to validate a comma delimited list like this one:

12365, 45236, 458, 1, 99996332, ...... 
like image 645
everLearningStudent Avatar asked Sep 08 '09 20:09

everLearningStudent


People also ask

How do you match a comma in regex?

The 0-9 indicates characters 0 through 9, the comma , indicates comma, and the semicolon indicates a ; . The closing ] indicates the end of the character set. The plus + indicates that one or more of the "previous item" must be present.

WHAT IS A in regex?

The power of regular expressions comes from its use of metacharacters, which are special characters (or sequences of characters) used to represent something else. For instance, in a regular expression the metacharacter ^ means "not". So, while "a" means "match lowercase a", "^a" means "do not match lowercase a".


1 Answers

I suggest you to do in the following way:

(\d+)(,\s*\d+)* 

which would work for a list containing 1 or more elements.

like image 146
Asaph Avatar answered Sep 20 '22 15:09

Asaph