I want to 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>
A sample file and a desired output file is attached to this post
Can anyone help me on this?
This is what I've tried so far
Dim targetDirectory AsString= TextBox1.Text
Dim txtFilesArray AsString()= Directory.GetFiles(targetDirectory,"*.txt")
ForEach txtFile In txtFilesArray
Dim input AsString= File.ReadAllText(txtFile)
Dim disp AsNew Regex("<disp-formula id=""deqn(\d+)-(\d+)"">")
Dim match As Match = disp.Match(input)
If disp.Matches()Then
Dim a AsInteger= match.Groups(1).Value
Dim b AsInteger= match.Groups(2).Value
ForEach c=a to b in input
Dim xref AsNew Regex("<xref[^>]+rid=""(?<id>deqn\d+-\d+)""[^>]*>(?<content>[^<]+)</xref>")
Dim result AsString= xref.Replace(input,Function(xyz)
???????
EndFunction)
Next
File.WriteAllText(txtFile, result)
EndIf
Next
A sample file and a desired output file is attached to this post
Can anyone help me on this?
This is what I've tried so far
Dim targetDirectory AsString= TextBox1.Text
Dim txtFilesArray AsString()= Directory.GetFiles(targetDirectory,"*.txt")
ForEach txtFile In txtFilesArray
Dim input AsString= File.ReadAllText(txtFile)
Dim disp AsNew Regex("<disp-formula id=""deqn(\d+)-(\d+)"">")
Dim match As Match = disp.Match(input)
If disp.Matches()Then
Dim a AsInteger= match.Groups(1).Value
Dim b AsInteger= match.Groups(2).Value
ForEach c=a to b in input
Dim xref AsNew Regex("<xref[^>]+rid=""(?<id>deqn\d+-\d+)""[^>]*>(?<content>[^<]+)</xref>")
Dim result AsString= xref.Replace(input,Function(xyz)
???????
EndFunction)
Next
File.WriteAllText(txtFile, result)
EndIf
Next