QRegExpValidator - help with regex for matching "1, 2, 3, 4-10, 20+"
Hi,
I need to limit the accepted inputs for a QLineEdit with a QRegExpValidator - but since I am not very familiar with RegExp, I am a bit confused how the RegExp I need would look like..
The Input can be a:
- A single number (eg. "1")
- A range (eg. "10-20")
- A infinite range (eg "10+" or "10-")
- Any combination of these comma-separated (eg "1, 2, 5, 10-30, 50+")
It is not important if the numbers in a comma-separated list make sense or are ascending, this would also be valid "5,2,13,4-20,3+,200-300,50-"
Any idea how I would do this with QRegExpValidator? Or any other nice solution?
Thanks,
Kira
Re: QRegExpValidator - help with regex for matching "1, 2, 3, 4-10, 20+"
Hi,
((\d+-\d+)|(\d+[+-]?)) should match one item r.
r(, *r)* should match a list of these items. Try:
Code:
QRegExp re
("^((\\d+-\\d+)|(\\d+[+-]?))(, *((\\d+-\\d+)|(\\d+[+-]?)))*$");
HTH, Bernd
Re: QRegExpValidator - help with regex for matching "1, 2, 3, 4-10, 20+"
http://regexpal.com/ is your friend ;)
There's a quick reference that might help you there.