I apologize in advance if this is a duplicate. I can’t imagine that they didn’t ask him before, but I couldn’t find him.
Why does the second C # operator throw an exception?
var regex = new Regex(@"\[IMG(?<image_number>[0-9]+)\]"); regex.Replace("[IMG1]", int.Parse("${image_number}").ToString());
I know that I can access a named group, but I cannot perform an operation on it - in this case int.Parse (). When I try to use a named group this way, it just gives me the string "$ {image_number}" - which, of course, cannot be parsed as an integer.
Thanks.
ek_ny source share