I need to verify if a string is a correctly formatted range of numbers in Python2.7, i mean the range that we use for example when choosing some specific pages to print, like this:
1,3,5-7, 10, 15 - 20
I would like it to accept white-spaces around the dashes and the comma, since often people tend to use white-spaces in such ranges:
I tried regex with not much luck. There is re.fullmatch in Python 3 that apparently only matches if the whole string matches the pattern, it does not exist in Python 2.7, however i tried this way of doing it in Python 2 withch apparently works properly but my regex seems to be wrong. I tried many different regexs and all of them failed in one or another way, the last one allowed wrong characters in the beginning of the line (this is for commas only, didn't get to dashes yet):
^\d+$|(\d+)(\s?)(,{1})(\s?)(\d+)
I am not bound to use the regex for this, however it would be nice to know how this can be fixed with regex.