I want trying make a program which will look for a expression <disp-formula id="deqn(\d+)-(\d+)"> in files and if there is one or more match, then it will search the whole file for expressions in the form <xref ref-type="disp-formula" rid="deqnX">(X)</xref> or <xref ref-type="disp-formula" rid="deqnX">X</xref> where X ranges from the first (\d+) to the last (\d+) and replace it to <xref ref-type="disp-formula" rid="deqn$1-$2">(X)</xref> or <xref ref-type="disp-formula" rid="deqn$1-$2">X</xref>. This is what I've come up with so far,
Can anyone help me on this??
Code
Dim targetDirectory As String = TextBox1.Text
Dim txtFilesArray As String() = Directory.GetFiles(targetDirectory, "*txt", SearchOption.AllDirectories)
For Each txtFile In txtFilesArray
Dim input As String = File.ReadAllText(txtFile)
Dim disp As New Regex("<disp-formula id=""deqn(\d+)-(\d+)"">")
Dim match As Match = disp.Match(input)
If match.Success Then
Dim a = match.Groups(1).Value
Dim b = match.Groups(2).Value
Dim d As String = a & "-" & b
For Each c = a To b In input
Dim xref As New Regex("rid=""deqn" & c & "")
Dim result As String = xref.Replace(input, "rid=""deqn" & d & "")
Next
End If
File.WriteAllText(txtFile, result)
NextCan anyone help me on this??



![[Image: 793854efd3c9ee7d90ddd413ae9deed6.png]](https://i.gyazo.com/793854efd3c9ee7d90ddd413ae9deed6.png)