Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx replace with calculations?

Tags:

c#

regex

Is it possible somehow to do a RegEx-replace with a calculation in the result? (in VS2010)

Such as:

Grid\.Row\=\"{[0-9]+}\"

to

Grid.Row="eval(int(\1) + 1)"
like image 776
Andreas Zita Avatar asked Sep 23 '26 04:09

Andreas Zita


1 Answers

You can use a MatchEvaluator do achieve this, like

 String s = Regex.Replace("1239", @"\d", m => (Int32.Parse(m.ToString()) + 1).ToString());

Output: 23410

Edit: I just noticed... if you mean "using the VS2010 find-replace feature" and not "using C#", then the answer is "no", i am afraid.

like image 53
Jens Avatar answered Sep 25 '26 18:09

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!