Regex works on regexr but not in app

133 Views Asked by At

I'm trying to convert a string like this "25²" to "25^2" for all superscripts. I'm using the following regex :

([\xB2\xB3\xB9\u2070\u2074-\u207B]+)

It works perfectly on regexr.com, but not in my app :

Regex.Replace(expr, @"([\xB2\xB3\xB9\u2070\u2074-\u207B]+)", delegate(Match match)
{
    string resu = "^(";
    match.ToString().All(x =>
    {
        resu += suptonb(x);
        return true;
    });
    resu += ")";
    return resu;
});
char suptonb(char sup)
{
    if (sup == '\xB2')
        return '2';
    if (sup == '\xB3')
        return '3';
    if (sup == '\xB9')
        return '1';

    if (sup == '\u2070')
             return '0';
    if (sup == '\u2074')
        return '4';
    if (sup == '\u2075')
        return '5';
    if (sup == '\u2076')
        return '6';
    if (sup == '\u2077')
        return '7';
    if (sup == '\u2078')
        return '8';
    if (sup == '\u2079')
        return '9';
    if (sup == '\u207A')
        return '+';
    if (sup == '\u207B')
        return '-';

    return ' ';
}

What's wrong with it ?

1

There are 1 best solutions below

0
On BEST ANSWER

AAH I don't believe I didn't see that.

I called Regex.Replace without assigning it to the variable (myvar = Regex.Replace)...

PROBLEM SOLVED