regex - Match nth number by regular expression(QRegularExpression) -
i trying match nth number in string.
ex : 0000_1111_2222_3333
the string[0] should 0000, string[1] should 1111 , on
following solution
qstring find_nth_match(qregularexpression const ®, qstring const &input, int nth) { auto = reg.globalmatch(input); qregularexpressionmatch match; int count = 0; while(it.hasnext()){ match = it.next(); if(count == nth){ return match.captured(1); } ++count; } return "no match"; }
i use following
qdebug()<<"nth match == "<<find_nth_match(qregularexpression("(\\d+)"), "0000_1111_2222_3333", 2);
it print "nth match == 2222"
it possible match nth number regular expression?
Comments
Post a Comment