I try it (QRegExp::capturedTexts() ) ,
find one ....
I try it (QRegExp::capturedTexts() ) ,
find one ....
what do you mean?
in your last post count() returned 3...
Better if you show your code, and not only explain the end effect.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
QString str="my name is bob,bobis good boy,i lick bob<";
QRegExp reg("bob");
reg.indexIn(str);
QStringList list=reg.capturedTexts();
qDebug() << list.count(); // output : 1
After a closer reading, it turns out capturedTexts() is not the right method you are looking for:
Some regexps can match an indeterminate number of times. For example if the input string is "Offsets: 12 14 99 231 7" and the regexp, rx, is (\d+)+, we would hope to get a list of all the numbers matched. However, after calling rx.indexIn(str), capturedTexts() will return the list ("12", "12"), i.e. the entire match was "12" and the first subexpression matched was "12". The correct approach is to use cap() in a loop.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
I'm read the Qt Assistant yesterday, I thinks should be :
Qt Code:
int count=str.count(reg); int from=0; int in=0; QStringList rs; for(int i=0;i<count;i++) { in=reg.indexIn(str,from); rs.append(reg.cap(0)); from=in+rs.value(i).size(); } qDebug() << rs.count(); //output 4(aa@g.com,a@g.com,qq@aaaa.com.cn,q@aaaa.com.cn) qDebug() << rs.value(0); //output "aa@g.com" qDebug() << rs.value(1); //output "qq@aaaa.com.cn" qDebug() << rs.value(2); //output "" qDebug() << rs.value(3); //output ""To copy to clipboard, switch view to plain text mode
how about thisis that ok?
and please check my regular expressions"[A-z0-9_\.-]+@[A-z0-9\.]+".
Last edited by fengtian.we; 31st May 2007 at 10:40.
OK!!!! Thank you everyone!
this is my way:
Qt Code:
int startPos=0; int mailPos=0; QStringList rs; while(true) { mailPos=reg.indexIn(str,startPos); if(mailPos<0) { break; } rs.append(reg.cap(0)); startPos=mailPos+rs.last().size(); } qDebug() << rs.count(); // 2 qDebug() << rs.value(0); // "aaa@g.com" qDebug() << rs.value(1); // "qq@aaaa.com.cn"To copy to clipboard, switch view to plain text mode
haha![]()
![]()
Bookmarks