I need a RegEx pattern that will allow me to substitute characters from one set to their corresponding characters in another set. for example: set [abcdefg], should be replaced with set [1234567]… So in a string of “bag”, i want my replacement to be “217”.
Regex regX = new Regex("([abcdefg])([1234567])");
string result = regX.Replace("bag", "$1$2");
My result is same as source. What should my replace pattern be?
Something like this will work much better than a Regex:
You could do something similar if you want, for example, ‘j’ to turn into ’10’, but you would need an array of Strings instead of being able to use a String as an array of chars.
I’m not sure how you would do this with a Regex, but I do know that you shouldn’t.