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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -