But with the classes Jpn suggested you can read QStrings from a file.
Read the docs to find out how you can do that.
Regards
But with the classes Jpn suggested you can read QStrings from a file.
Read the docs to find out how you can do that.
Regards
no Class QString is not supply any method to get it.
Are you sure?
What about this:
Qt Code:
return;To copy to clipboard, switch view to plain text mode
You can also read the stream in chunks, if the file is too big.
Regards
And here is a nice RegEx for email matching:
http://www.regular-expressions.info/email.html
==========================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.
yes , I can ,I can read the file now,
now , this string is a big string, a e-mail address in the string ,
I want get the e-mail address use regular expressions.. How TO
READ my last post.
==========================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);
qDebug() << str.count(reg); // output: 3OK
reg.indexIn(str);
reg.cap(0); // output: "bob"OK
reg.cap(1); // output: ""why
reg.cap(2); // output: ""why
Because I think you missunderstood the docs:
So QRegEx::cap(int n) does not retrieve the n'th match, but the match of the n'th parentheses in your expression, and you have only one (n=0) which is why only the first cap() returns a non empty string.Each subsequent element corresponds to the next capturing open left parentheses. Thus cap(1) is the text of the first capturing parentheses, cap(2) is the text of the second, and so on.
What you are looking for is QRegExp::capturedTexts() I think.
==========================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 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.
Bookmarks