Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The regular expression for numbers separated by either spaces or commas is:

\d+(?:[ ,]+\d+)*

Explanation: - \d+ matches one or more digits - (?:[ ,]+\d+)* matches zero or more occurrences of: - [ ,]+ which matches one or more spaces or commas - \d+ which matches one or more digits

This regular expression will match a string containing one or more numbers separated by spaces or commas. For example, it will match "1, 2, 3", "4 5, 6", "7", "8,9,10".