Reputation: 39
I had no problems with QRegExp class but now i have one. My Code
QRegExp re("d class=\\.green\\.>([+,0-9]+)<.td><td>[.0-9]+<.td><td>[.0-9]+<..n");
QString str=AliorLinia;
qDebug()<<str;
QStringList list;
int pos=0;
while((pos=re.indexIn(str, pos))!=-1){
list << re.cap(1);
pos+=re.matchedLength();
}
qDebug()<<list;
console show me
,line of str is on screen
console should show +0,10 but it show only () why :(?
Upvotes: 1
Views: 75
Reputation: 627327
You do not get a match because your real literal string looks like
d class="green">+0.10</td><td>69.7</td><td>69.0</
<NEWLINE>
The \"
and \n
you see in the debugger are just telling you the string literal contains a literal double quote and a newline symbol (a char with decimal code of 10).
Also, your number contains a .
, not ,
as a decimal separator, so you must add it to the [+,0-9]
character class.
So, your regex with minimal amendments can look like
QRegExp re("d class=.green.>([+.,0-9]+)<.td><td>[.0-9]+<.td><td>[.0-9]+<.\n");
See the regex demo
Upvotes: 1
Reputation: 9650
Because your regex pattern requires the green
attribute to be surrounded by dots literally - this is what \\.
stands for in a quoted string.
The regex you really want here is \\.
(i.e. a backslash literally followed by any character), that's right. But in a C string literal each of these two backslashes should be escaped by an extra slash:
QRegExp re("d class=\\\\.green\\\\.>([+,0-9]+)<.td><td>[.0-9]+<.td><td>[.0-9]+<..n");
^ ^ ^ ^
add these backslashes
Upvotes: 0