CSharp · Console
using System;
using System.Text.RegularExpressions;
public class Program
{
private static string ConvertSuperscriptToText(Match m){
string res = m.Groups[1].Value;
res = "^" + res;
return res;
}
public static void Main()
{
string expression = "2⁻¹² + 3³ / 4⁽³⁻¹⁾";
string desiredResult = "2^-12 + 3^3 / 4^(3-1)";
string supChars = "([¹²³⁴⁵⁶⁷⁸⁹⁰⁺⁻⁽⁾]+)";
string result = Regex.Replace(expression, supChars, ConvertSuperscriptToText);
Console.WriteLine(result); // Currently prints 2^⁻¹² + 3^³ / 4^⁽³⁻¹⁾
Console.WriteLine(result == desiredResult); // Currently prints false
}
}