I have VB.NET program that applies user supplied PATTERN and REPLACEMENT arguments to a collection of input strings using RegEx.Replace and special characters in the REPLACEMENT argument are not interpreted.
Is there a way to make RegEx.Replace interpret special characters in the REPLACEMENT string like it does in the PATTERN string? For example, treat "\t" as a tab and "\xAE" or "\u00AE" as (R)?
In Linux, I get the correct output from sed
echo Test XXX Replacement | sed 's/XXX/\xAE/'
gives "Test ® Replacement"
But in VB it just gives me the special character pattern as a literal
Regex.Replace("Test XXX Replacement", "XXX", "\t")
Regex.Replace("Test XXX Replacement", "XXX", "\u00AE")
gives "Test \t Replacement" and "Test \u00AE Replacement" respectively
I've found 2 somewhat related but distinctly not applicable posts, my problem differs from Escape Regex.replace() replacement string in VB.net in that I actually want the special characters in my replacement strings.
It also differs from Regex VB.Net Regex.Replace, that question had control of the replacement string and dodged my issue by using a VB constant instead of a RegEx special character.
Are there any settings/options/utilities/methods that can make my (user supplied!) RegEx REPLACEMENT strings correctly handle special characters?