Python 正则表达式:匹配两个单词之间的所有字符,返回奇怪的输出

Python 正则表达式:匹配两个单词之间的所有字符,返回奇怪的输出,python,regex,Python,Regex,在本文中: "IPAddress":"10.0.0.18","PolicerID":"","IPAddress":"","PolicerID":"" 我想捕获所有IP,在本例中是10.0.0.18和emptystring 我尝试使用这个正则表达式: (?<="IPAddress":")([^"]*) (?您可以保持简单,只需使用捕获组: >>> str = r'"IPAddress":"10.0.0.18","PolicerID":"","IPAddress":"",

在本文中:

"IPAddress":"10.0.0.18","PolicerID":"","IPAddress":"","PolicerID":""
我想捕获所有IP,在本例中是10.0.0.18和emptystring

我尝试使用这个正则表达式:

(?<="IPAddress":")([^"]*)

(?您可以保持简单,只需使用捕获组:

>>> str = r'"IPAddress":"10.0.0.18","PolicerID":"","IPAddress":"","PolicerID":""'
>>> print re.findall(r'"IPAddress":"([^"]*)', str)
['10.0.0.18', '']
>>>
但是,如果必须使用lookback断言,请使用以下正则表达式:

(?<="IPAddress":")([^"]*)

(?如果您希望该文本中的所有IP,我建议使用此正则表达式

[0-9]+(?:\.[0-9]+){3}

你的示例文本让我相信有一种更简单的方法可以做到这一点。你能发布更多的示例数据吗?如果你这么认为的话,它不是一个常规的json。更多的代码只是一些我不想共享的参数。是的……它不是常规的json,但是如果你添加
{
}
它就是。