1
Answer

Compiling multiple regex replaces in vb.net?

Is it possible to compile different regex replaces in vb.net? For example, I want to do the below replaces and that code that I have written is :
 
Dim pattern1 As String = "(figure|fig\.) (\d+)"
Dim pattern2 As String = "(table|tabl\.|tab\.) (\d+)"
Dim pattern3 As String = "(section|sect\.) (\d+)"
Dim pattern4 As String = "<disp-formula id=""deqn(\d+)" 
Dim rep1 As String = "<xref ref-type=""figure"" rid= ""fig$2"">$1 $2</a>"
Dim rep2 As String = "<xref ref-type=""table"" rid= ""tab$2"">$1 $2</a>"
Dim rep3 As String = "<xref ref-type=""section"" rid= ""sec$2"">$1 $2</a>"
Dim rep4 As String = "\r\n<disp-formula id=""deqn$1" 
Dim rgx1 As New Regex(pattern1, RegexOptions.IgnoreCase)
Dim rgx2 As New Regex(pattern2, RegexOptions.IgnoreCase)
Dim rgx3 As New Regex(pattern3, RegexOptions.IgnoreCase)
Dim rgx4 As New Regex(pattern4, RegexOptions.IgnoreCase) 
Dim result1 As String = rgx1.Replace(input(x), rep1)
Dim result2 As String = rgx2.Replace(result1, rep2)
Dim result3 As String = rgx3.Replace(result2, rep3)
Dim result4 As String = rgx4.Replace(result3, rep4) 
input = result4
 
How do I compile all this replaces to a single or much less lengthy coding?
 
Answers (1)