PDA

View Full Version : Help with a regular expression.



ayanda83
10th March 2017, 08:59
Hi there guys, I am trying to put together a regular expression for pulling out data from the html below. The text I am interested in, is in line 3,22, and "href" of line 25. I have have put together this regular expression for line 25 and it works perfectly
<a\\s+class=\"linkDetails\"\\s+href=\"(.*)\"\\s+target=\"_blank\"\\s+title=\"Details\">I would like to extend the above regular expression to retrieve line 3 and 22 as well and through the use of QRegExp::cap(), I can store the data accordingly in a QStringList. I could use a little help with extending the R.E.
<tr class="gridDetails">
<td style="width: 70px;">
R01170512A
</td>
<td>

Gloves;nytrile, heavy duty;10
</td>
<td style="width: 100px; padding-right: 10px;">
Clothing - PPE &amp; Accessories
</td>
<td style="width: 70px; padding-right: 10px;">
2017/03/15
</td>
<td style="width: 70px; padding-right: 10px;">
3/15/2017 10:00:00 AM
</td>
<td style="width: 70px; padding-right: 10px;">
2017/03/09
</td>
<td style="width: 70px; padding-right: 10px;">
3/9/2017 9:59:27 AM
</td>
<td style="width: 10px; padding-right: 5px; padding-left: 5px;">
<a class="linkDetails" href="/web1/ProcurementPortal/RFQ/Details/123668" target="_blank" title="Details"> </a>
</td>
</tr>
<tr class="gridDetails">
<td style="width: 70px;">
R01170554A
</td>
<td>

Overall trousers;white;34/87cm
</td>
<td style="width: 100px; padding-right: 10px;">
Clothing - PPE &amp; Accessories
</td>
<td style="width: 70px; padding-right: 10px;">
2017/03/15
</td>
<td style="width: 70px; padding-right: 10px;">
3/15/2017 10:00:00 AM
</td>
<td style="width: 70px; padding-right: 10px;">
2017/03/09
</td>
<td style="width: 70px; padding-right: 10px;">
3/9/2017 9:59:27 AM
</td>
<td style="width: 10px; padding-right: 5px; padding-left: 5px;">
<a class="linkDetails" href="/web1/ProcurementPortal/RFQ/Details/123667" target="_blank" title="Details"> </a>
</td>
</tr>

Santosh Reddy
10th March 2017, 13:25
Can't you just parse the file and pick the required tags.

ayanda83
10th March 2017, 13:33
I tried using QDom classes to parse but it turns out that QDom classes don't work with html, so I tried using external libs like libxml++ and libxml2 but I got a bunch of linker errors I could not figure out. What can I use to parse html in Qt? thanking you in advance.

d_stranz
11th March 2017, 02:46
See the answer at this stackoverflow link (http://stackoverflow.com/questions/18676800/how-to-parse-html-with-c-qt) on using QXmlQuery to parse HTML.