小编Lar*_*din的帖子

python正则表达式重复字符串

我想验证然后解析这个字符串(在引号中):

string = "start: c12354, c3456, 34526; other stuff that I don't care about"
//Note that some codes begin with 'c'
Run Code Online (Sandbox Code Playgroud)

我想验证字符串以'start:'开头并以';'结尾 之后,我想要一个正则表达式解析字符串.我尝试了以下python重新代码:

regx = r"start: (c?[0-9]+,?)+;" 
reg = re.compile(regx)
matched = reg.search(string)
print ' matched.groups()', matched.groups()
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的变化,但我可以得到第一个或最后一个代码,但不是所有三个的列表.

或者我应该放弃使用正则表达式?

编辑:更新,以反映我忽略的问题空间的一部分,并修复字符串差异.感谢所有的建议 - 在这么短的时间内.

python regex parsing

2
推荐指数
2
解决办法
6447
查看次数

标签 统计

parsing ×1

python ×1

regex ×1