Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Using regex match function to modify data?

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,

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)
        Next

Can anyone help me on this??
Why not use some sort of XML parser? There's a gazillion of them built in to the .NET framework and all of them would make this much, much easier.
New to trading cryptocurrencies but don't know where to start? Join Binance here! Binance is my favourite exchange for cryptocurrencies w/ low fees.

[Image: 793854efd3c9ee7d90ddd413ae9deed6.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by zlg43647Oct 28, 2022 07:06 AM 2 240 Oct 28, 2022 07:06 AM
Last Post: zlg43647
[C] by FhackMar 2, 2022 03:52 AM 4 304 Mar 2, 2022 03:52 AM
Last Post: Fhack
[C#] by mayar2021Mar 14, 2021 03:44 PM 7 291 Mar 14, 2021 03:44 PM
Last Post: sniper coder