I have a .csv file and I'm only interested in rows with comma delimeted integers:
23,2,4,56,78,9,4,6
The number of comma delimited values in a row should be more than 5 (or whatever).
I'm doing this in perl.
I have a .csv file and I'm only interested in rows with comma delimeted integers:
23,2,4,56,78,9,4,6
The number of comma delimited values in a row should be more than 5 (or whatever).
I'm doing this in perl.
/^(\d+,){4,}\d+$/
Match a set of digits, followed by a comma. The digit-comma pair is treated as a group, which itself has to be repeated at least four times. Then you match the final number in the sequence which doesn't need to be followed by a comma.
If you don't need to capture the digits, use non-capturing groups instead (will be marginally faster):
/^(?:\d+,){4,}\d+$/
For whatever:
/^([0-9]\+,?)\+$/
Edited to correct the error pointed out in the comment.
/\d{1,3}(,\d{3}){0,4}/
This will only match properly formatted comma delimited numbers (100,000,000 for instance). It is still a terrible idea to have comma delimited numbers in a comma separated file, but I digress. That regex is the least likely to have problems in the context.
/\d+(?:,\d+)*/
or including negative numbers
/-?\d+(?:,-?\d+)*/
You may want to consider using [0-9] instead of \d, since \d can match things that Unicode considers numbers but aren't the standard Arabic numerals.