I need to build a regex that does some specific matches but I'm a novice and need some help. I need the regex to match to the 11th character only when the follow criteria are present in the string.
- total string is 19 characters long
- the first 10 characters are numeric
- the 11th character is 1
- the 12th - 19th characters are alphanumeric
I need to then replace the 11th character with an "I"
CodePudding user response:
You could use pattern: ^(\d{10})(\d)(\w{8})$
var pattern = new Regex(@"^(\d{10})(\d)(\w{8})$");
var input = "01234567891ABCD1234";
var output = pattern.Replace(input, "$1I$3");