Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 46
Registered: ‎03-25-2011
My Device: Blackberry Z10
My Carrier: KPN




i need to grep a src from image tag (scrap it from html fetched from url)


QString html = reply->readAll();

QRegExp regex("<div class=\"cartoon\">\\s*<img src=\"(.*?)\""); << regex should be valid tested it in regexbuddy

// match found
// no match found


this always said no match found,


this is html content that i need to get it from:


<<<< LOTS OF HTML >>>>>
<div class="cartoon">
                <img src="content/formfield_files/formcartoon_9318_10f4dc0f11576960405b60e024a2e54e7dcdfd3b.gif" width="468" height="292" alt="F&amp;S werken op de eerste hulp (NRC, za, 23-02-13)" />
                <div class="selectcartoon"><span class="week">week 08</span><a href="/nl?cm=79&amp;ctime=1362178800"><img src="images/default/moveright.gif" width="16" height="15" alt="" /></a><br /><a href="/nl?cm=79&amp;ctime=1361142000" class="day">maandag</a> &nbsp;<a href="/nl?cm=79&amp;ctime=1361228400" class="day">dinsdag</a> &nbsp;<a href="/nl?cm=79&amp;ctime=1361314800" class="day">woensdag</a> &nbsp;<a href="/nl?cm=79&amp;ctime=1361401200" class="day">donderdag</a> &nbsp;<a href="/nl?cm=79&amp;ctime=1361487600" class="day">vrijdag</a> &nbsp;<a href="/nl?cm=79&amp;ctime=1361574000" class="day active">zaterdag &amp; zondag</a></div>
<<<<< MORE HTML >>>>>

 now i only need this part:


Posts: 207
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10
My Carrier: Verizon

Re: Regex

[ Edited ]

I would change your regex to this:


QRegExp regex("<div class=\"cartoon\">.*<img src=\"(.*)\"");


Edit: this may be a better example of what to do:


QRegExp rx("(\\d+)(\\s*)(cm|inch(es)?)");
int pos = rx.indexIn("Length: 36 inches");
QStringList list = rx.capturedTexts();

 So I would modify my answer to be:


QRegExp regex("<div class=\"cartoon\">.*<img src=\"(\\s*)\"");
int pos = regex.indexIn(html);
if (pos != -1)
   // it matches
   // it doesnt


Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook