PDA

View Full Version : regular expressions



been_1990
8th November 2010, 13:57
I'm trying to match numbers in a row separated by a coma.
Ex: 1,1,1,1,1,0,0,0,0,0,1

If I use this "[0-9]," in the regexdialog Qt example, it works. But what if my row of numbers is: 12,123,1,1,0,0,12,0,0,0,1 ?
How can I match any number that comes before a coma, and the last one?

SixDegrees
8th November 2010, 14:03
"[0-9]{1,3},*"

Assuming your numbers always have between 1 and three digits.

tbscope
8th November 2010, 14:37
or:
[0-9]*,

bred
8th November 2010, 14:47
and:

[\d]{1,3}\,{0,1}

the sequence \d is equivalent to 0-9
to match the comma we must write \,

or
^[\d]{1,3}[\,]{0,1}

http://doc.qt.nokia.com/4.7/qregexp.html

wysota
8th November 2010, 14:47
Or:
\d+,

If you wish to catch the last one as well then:
\d+,?

been_1990
8th November 2010, 17:10
Thanks for the help. [0-9]{1,3} solves the problem.