Regex to find percent sign with actual math value

.net, c#, regex, replace, vb.net

Solution

If the percent doesn't occur in any other situation in the string, you don't even need a regular expression:

s = s.Replace("%", "/100");

To add the parentheses you need the regular expression though:

s = Regex.Replace(s, @"(\d{1,3})%", "($1/100)");

Problem

I have a string like `30+20%`. Now I want to replace `20%` with `(20/100)`. Thats it.

Original source

Related problems