I have a function to extract items from a web page. I use Match.NextMatch() within a loop. However, the code appends each item extracted from the source document TWICE. It is as if the Match.Value string is not cleared until you append it. Here is the function:

Private Function ExtractItemFromPage(sSource as String) As Boolean

Dim expr As New Regex("\b\d{3}\s\d{3}-\d{4}") '-- Get phone number --

Dim m As Match = expr.Match(sSource)

Do While m.Success

txtPhoneNums.AppendText(m.Value & vbCrLf)

m = m.NextMatch


Return True

End Function

Why is this appending the same number twice Do I need to call some function to clear the value of m.Value before I call NextMatch()

Re: Regular Expressions match.value not cleared??


I ran your code snippet and also tested the regex pattern in a stand-alone regex parser and it only gets one match on a number such as

555 867-5309

Are you calling this function twice

Re: Regular Expressions match.value not cleared??


Yes, it appears I was calling the function twice. Sorry for the stupid question.