All I am trying to extract two numbers from a user string. I have the regexp working, but the second number capture is not being greedy enough! I can’t figure out how to reformat this to my needs, I am submitting my reg exp any advice would be great!
QRegExp valid_input(".*(-?\\d*\\.?\\d+)[\\s,]+(-?\\d*.?\\d+)[^\d]*");
valid_input.setMinimal(true);
if(valid_input.indexIn(value.toString()) == -1)
return false;
QPointF new_point(valid_input.cap(1).toDouble(), valid_input.cap(2).toDouble());
Thanks in advance!
Example input: 156, 264
Expected Output: 156 and 264
My Output: 156 and 2
Example input: 156.2 264.52
Expected Output: 156.2 and 264.52
My Output: 156 and 2
Example input: 156.2 264.52)
Expected Output: 156.2 and 264.52
My Output: 156 and 2
Your regex works fine with your examples. Simply do not enable minimal matching and you will get the expected results.