Replacing strings using regular expressions in multiple files in vb.net

I’m looking to build a simple text string replacement tool using visual studio 2015 community tool, which will do the below replacements on all *.txt files whose path is given in a textbox:

Find: <figure (\d+)>
Replace: figure \1
Find: <table (\d+)>
Replace: table \1
Find: <section (\d+)>
Replace: section \1
I have coded the programme but struggling to successfully run it. I’m completely new in programming and in visual basic is well. Can anyone help complete this programme

```

Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If FBD.ShowDialog = DialogResult.OK Then
TextBox1.Text = FBD.SelectedPath
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim targetDirectory As String
targetDirectory = TextBox1.Text
Dim Files As String() = Directory.GetFiles(targetDirectory, “*.txt”)
Dim pattern1 As String = “<figure (\d+)>”
Dim pattern2 As String = “<table (\d+)>”
Dim pattern3 As String = “<section (\d+)>”
Dim rep1 As String = "<a href id= ““fig\1"” > figure \1”
Dim rep2 As String = "<a href id= ““tab\1"” > table \1”
Dim rep3 As String = "<a href id= ““sec\1"” > section \1”
Dim rgx1 As New Regex(pattern1)
Dim rgx2 As New Regex(pattern2)
Dim rgx3 As New Regex(pattern3)
Dim result1 As String = rgx1.Replace(Files, rep1)
Dim result2 As String = rgx2.Replace(Files, rep2)
Dim result3 As String = rgx3.Replace(Files, rep3)
End Sub
End Class

<do not remove the three backticks above>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.