Kevin Burt

Kevin Burt

  • NA
  • 3
  • 0

Regex.Replace() - Is it possible to increment/decrement group values in-line?

Mar 31 2008 11:54 AM

Hello.

Does anyone know if it is possible to increment/decrement values in a Regex Group?

For example, the following code demonstrates capturing two groups called 'value1' and 'value2', and I would like to replace these value with (value1+1) and (value2-1) respectively.

string pattern = @"(?<value1>\d{1,2})/(?<value2>\d{1,2})";

string result = Regex.Replace(myString, patten, @"${value1}+1/${value2}-1");

I'm basically looking to manipulate multiple numeric values on a multi-line chunk of text.

Any advice would be much appreciated.


Answers (2)