我在论坛上进行了一些搜索,试图用似乎适用的所有解决方案删除项目符号。
“弗里蒙特·全日制”
关于如何分割字符串以仅提取“ Fremont”的任何想法吗?
我目前有删除子弹的方法,但是出现以下两个错误:
string.replace('/\d\.\s+|[a-z]\)\s+|[A-Z]\.\s+|[IVX]+\.\s+/g', "")
这根本不影响更改字符串,这告诉我正则表达式查询无法识别细小项目符号
string.replace('/\d\.\s+|[a-z]\)\s+|•\s+|[A-Z]\.\s+|[IVX]+\.\s+/g', "")
这给出了以下错误:
UnicodeDecodeError:'ascii'编解码器无法解码位置20的字节0xe2:序数不在范围内(128)
也尝试过这种方式
bullet = u"\u2022"
string =u"Fremont · Full Time"
string2 = string.replace(bullet, "A")
newStr = re.sub(regex, "", string)
没有效果
有任何想法吗?
这会做到的
import string
string_to_replace = "Fremont · Full Time"
regex = '\xc2\xb7'
string.replace(string_to_replace, regex, '')
我是怎么发现的
>>> a = "Fremont · Full Time"
>>> a.split()
['Fremont', '\xc2\xb7', 'Full', 'Time']
>>> import string
>>> string.replace(a,'\xc2\xb7',"")
'Fremont Full Time'
[编辑]
正如Joey正确指出的那样,这取决于系统的编码。该split
功能应该有助于弄清楚项目符号是如何在您的系统中编码的,以及希望代码在其上运行的系统。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句