I am having an issue where I am using regex.Replace to replace part of a string. The basic idea is that I want to capture the beginning of the string then replace the end of the string with a value from code. For an example pretend I have a string that says "Test Number " followed by number and I want to increment that number. I capture the "Test Number " but when I try to concatenate that capture with the new number it treats the capture ($1) as a literal and replaces the entire string with $1[new number].
Dim s as String = "We are on Test Number 1"
Dim newNumber as Integer = 2
s=Regex.Replace(s,"(Test Number )(\d)","$1" & newNumber)
This will output "We are on $12". However, if I use a literal in the replace, the issue doesn't happen.
Dim s as String = "We are on Test Number 1"
s=Regex.Replace(s,"(Test Number )(\d)","$1" & "2")
This will output "We are on Test Number 2", as expected.
Does anyone have any thoughts on how I can use a variable in the replacement string portion of the Regex.Replace when including a captured group?
Thanks in advance.