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]*"); 

demo


Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

How to connect android app to App engine -

hadoop - Running Map Reduce Job shows error - Mkdirs failed to create /var/folders/ -