我有一些这样的文字:
GAEDS030, GAEDS031, GAEDS032 : Problem reported in a https://twikiae.myweb.es
/twiki/bin/view/Grid/ActFeb2011 previous entry has been observed in another disk server
that was under a stress test (gaeds034). We have contacted technical service at LSI and
they have suggested us to update to a brand new firmware (!FE9X 4.10.00.021). After a new
test period if seems that raid card does not reset under heavy load as in the past. So it
has been upgraded every card of this branch (gaeds030-gaeds034)
他们中的一些人没有结肠。
现在我使用此正则表达式在第一个:
之后和第一个.
re.search(':([^\.]*)(\.)*', description)
并且当它没有:
re.search('((.*)(?!\. ))', description)
正如您所看到的,当有URL,IP等时我会遇到问题,因此我希望在:
之前.
之后捕获文本(点后跟空格)。< / p>
我尝试过白色否定套装,但它不允许在群组中使用它们。
答案 0 :(得分:0)
答案 1 :(得分:0)
由于输入中存在换行符,因此最好使用DOTALL modifier (?s)
使点与新行字符匹配。这样就可以在多行上进行匹配。
(?<=:\s).*?(?=\.\s)
>>> s = """GAEDS030, GAEDS031, GAEDS032 : Problem reported in a https://twikiae.myweb.es
... /twiki/bin/view/Grid/ActFeb2011 previous entry has been observed in another disk server
... that was under a stress test (gaeds034). We have contacted technical service at LSI and
... they have suggested us to update to a brand new firmware (!FE9X 4.10.00.021). After a new
... test period if seems that raid card does not reset under heavy load as in the past. So it
... has been upgraded every card of this branch (gaeds030-gaeds034)"""
>>> re.search(r'(?s)(?<=:\s).*?(?=\.\s)', s).group()
'Problem reported in a https://twikiae.myweb.es\n/twiki/bin/view/Grid/ActFeb2011 previous entry has been observed in another disk server\nthat was under a stress test (gaeds034)'
>>> m = re.search(r'(?s)(?<=:\s).*?(?=\.\s)', s).group()
>>> print m
Problem reported in a https://twikiae.myweb.es
/twiki/bin/view/Grid/ActFeb2011 previous entry has been observed in another disk server
that was under a stress test (gaeds034)
答案 2 :(得分:0)