由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DataSciences版 - python re non greedy question
相关主题
克劳迪亚 管理员 培训材料职业发展请教大家
text mining中的relation extraction请教几个问题
datascientist几个基本问题julia有前途吗? (转载)
大数据时代的最大挑战(一)?求教! how to run python programs on a hadoop cluster
求问Facebook的data scientist ETL interview (转载)Machine learning in action by Peter Harrington
问个大数据的问题问个问题。
假如想实现 entity recognition, relation extraction这些功能的话,除了GATE, 还有 哪些其它的open source library。哪位大侠给推荐个scientific plotting lib/software
Locality Sensitive Hashing 问题理论化学女生想转行,求建议
相关话题的讨论汇总
话题: greedy话题: get话题: non话题: numbers
进入DataSciences版参与讨论
1 (共1页)
s****h
发帖数: 3979
1
I have a string,'a1a2a3a4a5a6a', and want to extract all numbers:
['1', '2', '3', '4', '5', '6']
However, I can only get the odd numbers:
print re.findall('a(.+?)a' , 'a1a2a3a4a5a6a')
['1', '3', '5']
My guess:
non greedy re.findall could only find 'a1a' and get '1',
then do re.findall('a(.+?)a' , '2a3a4a5a6a'), find 'a3a' and get '3', and so
on.
Any suggestion?
m*********r
发帖数: 119
2
yes, because you add 'a' at last,
use re.findall('a(.+?)' , 'a1a2a3a4a5a6a') instead
D**u
发帖数: 288
3
只要数字的话re.findall('\d', 'a1a2a3a4a5a6a') 就好了吧
s****h
发帖数: 3979
4
多谢回复
其实用re.split就行了。
这里的a,数字,其实都是一些字符串。
我是改自己以前的code,以前的那个case,pattern是'a(.+?)b'。前后的字符串不一样
c*******n
发帖数: 679
5
'a1a2a3a4a5a6a'.split('a')[:-1]

so

【在 s****h 的大作中提到】
: I have a string,'a1a2a3a4a5a6a', and want to extract all numbers:
: ['1', '2', '3', '4', '5', '6']
: However, I can only get the odd numbers:
: print re.findall('a(.+?)a' , 'a1a2a3a4a5a6a')
: ['1', '3', '5']
: My guess:
: non greedy re.findall could only find 'a1a' and get '1',
: then do re.findall('a(.+?)a' , '2a3a4a5a6a'), find 'a3a' and get '3', and so
: on.
: Any suggestion?

l*******s
发帖数: 1258
6
实在想match的精确些 试试往前往后看
(?<='a')\d(?='a')
1 (共1页)
进入DataSciences版参与讨论
相关主题
理论化学女生想转行,求建议求问Facebook的data scientist ETL interview (转载)
data scientist考coding的题目可以用python吗?问个大数据的问题
求教如何从网页抓取数据假如想实现 entity recognition, relation extraction这些功能的话,除了GATE, 还有 哪些其它的open source library。
说说浅学ML的感受Locality Sensitive Hashing 问题
克劳迪亚 管理员 培训材料职业发展请教大家
text mining中的relation extraction请教几个问题
datascientist几个基本问题julia有前途吗? (转载)
大数据时代的最大挑战(一)?求教! how to run python programs on a hadoop cluster
相关话题的讨论汇总
话题: greedy话题: get话题: non话题: numbers