Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove powered number from string in python

I want to remove the power of number from string. how can I do that? for example the number is:

I know its Unicode is :1\u2071

I find this:

 text = re.sub("(\([^)]*\)|\w)\^(\([^)]*\)|\w)", ' ', text)

but not works.

like image 817
sara aaa Avatar asked Jun 22 '26 02:06

sara aaa


2 Answers

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+[²³¹⁰ⁱ⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿ]+

Demo

like image 196
Sweeper Avatar answered Jun 23 '26 14:06

Sweeper


import re
test = '1¹'
text_n = re.sub("(¹)", ' ', test)
print (text_n)

https://rextester.com/NHXV37698