Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am looking for a regex that can take a comma separated line of ranges. Something like '1-5, 20-250, 37000-41000'
Regex needs to follow these rules:
1. should be able to take any number of ranges. For example" '1-25' would work. So would '1-25,67-324'. So would '1-15, 76-102, 56-98'
2. should be able to handle spaces between ranges
3. should fail if there are decimals, or non-digits in range: '1-25,28-43.5' should fail. '1-2a, 45-98' should fail.
Any tips much appreciated. My biggest hurdle is trying to figure out how to match a pattern against a string of indeterminate length/content.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for a flexible regex...
by BrowserUk (Patriarch) on Sep 19, 2013 at 15:40 UTC | |
by Anonymous Monk on Sep 19, 2013 at 15:46 UTC | |
by aaron_baugher (Curate) on Sep 21, 2013 at 13:14 UTC | |
by Anonymous Monk on Sep 22, 2013 at 03:45 UTC | |
by BrowserUk (Patriarch) on Sep 22, 2013 at 07:10 UTC | |
by Anonymous Monk on Sep 22, 2013 at 16:09 UTC | |
|
Re: Looking for a flexible regex...
by hippo (Archbishop) on Sep 19, 2013 at 15:35 UTC | |
|
Re: Looking for a flexible regex...
by daxim (Curate) on Sep 19, 2013 at 15:38 UTC | |
|
Re: Looking for a flexible regex...
by CountZero (Bishop) on Sep 22, 2013 at 08:58 UTC | |
|
Re: Looking for a flexible regex...
by BillKSmith (Monsignor) on Sep 20, 2013 at 03:43 UTC |