• 0

Modify linking tags after analyzing some data in a file?


Question

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>. I've written a portion of the code and I'm stuck

 

Dim targetDirectory As String = TextBox1.Text
        Dim txtFilesArray As String() = Directory.GetFiles(targetDirectory, "*.txt")
        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 disp.Matches() Then
                Dim a As Integer = match.Groups(1).Value
                Dim b As Integer = match.Groups(2).Value
                For Each c=a to b in input
                       
                 ???????
                Next

                File.WriteAllText(txtFile, result)
            End If
        Next

Can anybody help me on this? I've also attached one input sample and one desired output file to the post.

desired_output.png

sample_input.png

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.