I want to remove the power of number from string. how can I do that? for example the number is:
1¹
I know its Unicode is :1\u2071
I find this:
text = re.sub("(\([^)]*\)|\w)\^(\([^)]*\)|\w)", ' ', text)
but not works.
What you have found seems to match expressions like x^y, where the superscript is expressed with the ^ character.
However, the strings you are trying to match uses actual superscript characters, which are limited to these:
²³¹⁰ⁱ⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿ
Therefore, you could just create a character class with those:
\d+[²³¹⁰ⁱ⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿ]+
import re
test = '1¹'
text_n = re.sub("(¹)", ' ', test)
print (text_n)
https://rextester.com/NHXV37698
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With