正規表現が一致した場合の正規表現をカウントするためにすべての行を読み取るのに問題があり、<a href=
その行をスキップして最後まで終了しません。たとえば、ここには 2 つの<a href
タグがありますが、最初のタグを読み取った後、次の行にジャンプします。
"<p class="txt">Everyone seemed cool with that, including Coach A, so we went to work putting it all together. The end result had us starting off standing in a <strong>V formation</strong><a href="../Text/chap5.html#b1" id="f1">*</a>, and then the girls in back would tumble forward so that we were all in a straight line for the cheer. It was a really cool idea! To finish things off, we’d transition into two stunt groups that would do side-by-side <strong>elevators</strong><a href="../Text/chap5.html#b2" id="f2"></a>.</p>"
これが私のコードです:
Dim count1 As Integer = 0
For p As Integer = 0 To lvw.Items.Count - 1
Dim r As StreamReader = New StreamReader(New FileStream(Path.Combine(lvw.Items(p).Tag, lvw.Items(p).Text), FileMode.Open, FileAccess.Read, FileShare.Read))
Do While Not r.EndOfStream
Dim strr1 As String = r.ReadLine.Trim
Try
Dim regex As Regex = New Regex("<a\s+[^>]*(href\s*=\s*(['""]).*?\2)")
Dim m As Match = regex.Match(strr1)
If m.Success Then
count1 += 1
End If
Label2.Text = (count1.ToString)
Catch ex As Exception
End Try
Loop
Next