In my program, I convert an invoice pdf to text. I am looking for a better Regex Expression to parse the string. The results of my conversion are a very long string:
This is a very long string. Invoice Total: $1,399.52 Continuation of very long string.
I want to parse out the 1399.52 Following the "Invoice Total:".
Here is my first attempt:
Dim text As String = "This is a very long string. Invoice Total: $1,399.52 Continuation of very long string."
Dim re As Regex = New Regex("Invoice Total:\s*\$((\d|\.)*)")
Dim m As Match = re.Match(text)
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}] = {1}", re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
If(groupIdx = 1) Then
txtTotal.Text = m.Groups(groupIdx).Value
End If
Next
Matches Found:
[0][0] = Invoice Total: $1,399.52
[0][1] = 1399.52
[0][2] = 0
The code works, but I know there is a better way.