c# - Regex replace with string that contains a character from the origianal -
can regex replace pattern in string string contains character original? example:
x(#2(3)) -> x([0-9]{3})[0-9]*
x(#6(1)) -> x([0-9]{1})[0-9]*
x(#9(4)) -> x([0-9]{4})[0-9]*
in each case, bolded number placed in new string. possible regex? if not, can efficient solution this?
yep, it's possible regex using capturing group.
regex.replace(str, @"x\(#\d+\((\d+)\)\)", "x([0-9]{$1})[0-9]*");
Comments
Post a Comment