Python Regex从以下字符串返回AM

时间:2013-06-13 03:11:56

标签: python regex

我的输入就像这个例子:

hxxp://192.179.110.10:82/starvision.tk?server_time=6/12/2013 6:52:53 AM&hash_value=

我想要一个python正则表达式,它返回第二个空格和字符&之间的字符串,在本例中为AM

2 个答案:

答案 0 :(得分:1)

表达式是

hxxp[^ ]* [^ ]* ([^&]*)&

并且第1组将包含您的“am”

答案 1 :(得分:0)

>>> import re
>>> re.findall('\w+(?=&)', 'hxxp://192.179.110.10:82/starvision.tk?server_time=6/12/2013 6:52:53 AM&hash_value=')
['AM']

编辑:

>>> re.findall('server_time=[^&]+?(\w+)&', 'hxxp://192.179.110.10:82/starvision.tk?server_time=6/12/2013 6:52:53 AM&hash_value=bcd&ddd=aaa')
['AM']