我正在尝试获取一些被<td>
标签包围的文本。我的问题是我只能获取第一个结果,而无法获取其他结果。
从以下 HTML 中,我只得到第一个结果,即此文本:
学生姓名
但是所有其他捕获其余所需文本的尝试都是空的,null。为什么会这样&我做错了什么?
用于正则表达式的文本:
<table width="52%" border="1" align="center" cellpadding="1" cellspacing="1">
<tr>
<td colspan="2" align="center" bgcolor="#999999">Result</td>
</tr>
<tr>
<td width="22%"><strong>Student ID</strong></td>
<td width="78%">13/0003337/99</td>
</tr>
<tr>
<td><strong>Student Name</strong></td>
<td>Alaa Salah Yousuf Omer</td>
</tr>
<tr>
<td><strong>College</strong></td>
<td>Medicine & General Surgery</td>
</tr>
<tr>
<td><strong>Subspecialty</strong></td>
<td>General</td>
</tr>
<tr>
<td><strong>Semester</strong></td>
<td>Fourth</td>
</tr>
<tr>
<td><strong>State</strong></td>
<td>Pass</td>
</tr>
<tr>
<td><strong>Semester's GPA</strong></td>
<td>2.89</td>
</tr>
<tr>
<td><strong>Overall GPA</strong></td>
<td>3.13</td>
</tr>
</table>
我的代码:
QString resultHTML = "A variable containing the html code written above."
QRegularExpression regex("<td>(.*)</td>", QRegularExpression::MultilineOption);
QRegularExpressionMatch match = regex.match(resultHTML);
// I only get the 1st result logged withing debugger
for(int x = 0; x <= match.capturedLength(); x++)
{
qDebug() << match.captured(x);
}
// This here doesn't get me anything, null!
_studentName = match.captured(2);
_semesterWritten = match.captured(8);
_stateWritten = match.captured(10);
_currentGPA = match.captured(12);
_overallGPA = match.captured(14);