Why can't I use python strip () to remove the beginning and end of Chinese characters?

se=
se.strip (u "[u4e00-u9fa5] +")
"my Love 3453454 good composition"
se.strip (u "[u4e00-u9fa5] +")
"my Love 3453454 good composition"
se=u "my Love 3453454 good composition"
se.strip (u "[u4e00-u9fa5] +")
"my Love 3453454 good composition"
se.strip (u "[u4e00-u9fa5]") < [u4e00-u9fa5] ")
"my Love 3453454 good composition"
Mar.20,2021
The parameters of

strip () do not support regular expressions. The parameters are character sequences. If the string ends in that sequence, delete it. For example:
In [1]: se = "+ dwjsdd"
In [2]: se
Out [2]:'\ + dwjsd\ d'
In [3]: se.strip ("d +")
Out [3]: 'wjs'


import re
s1 = "3453454"
s2 = "3453454123432"

p = re.compile("[^\u4e00-\u9fa5]+")

print([i.group() for i in p.finditer(s1)])
print([i.group() for i in p.finditer(s2)])

try this method.

Menu