这是一个创建于 3776 天前的主题,其中的信息可能已经有所发展或是发生改变。
用的是python3.3.5 IDE是pycharm
我想取出标签、汉字、单词、数字、和空格
代码如下
import re
regex = re.compile("<[^>]*>|[\u4e00-\u9fa5]|[a-zA-Z]*|\d*|\s*")
print(regex.findall('''<i> bob是</i>25岁<br/>'''))
结果是
['<i>', '', 'bob', '是', '</i>', '', '', '岁', '<br/>', '']
想请教一下为什么数字25取不出来?
3 条回复 • 2014-06-21 17:48:03 +08:00
|
|
1
forreal 2014-06-21 16:42:39 +08:00
第二行代码改为 regex = re.compile(r"<[^>]*>|[\u4e00-\u9fa5]|[a-zA-Z]*|\d*") 还是取不到数字25
|
|
|
2
czheo 2014-06-21 17:44:02 +08:00 1
把所有的* 改成+ 试试
|
|
|
3
forreal 2014-06-21 17:48:03 +08:00
|