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 &reg, 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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -