Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正则表达式否定不起作用_Python_Regex_Regex Negation - Fatal编程技术网

Python 正则表达式否定不起作用

Python 正则表达式否定不起作用,python,regex,regex-negation,Python,Regex,Regex Negation,所以我试图否认这个模式,但它不起作用,即使我用一个简单的例子来概括它。我想这是把它和锚搞混了,但我找不到一个办法来回避这个问题。我检查了其他问题,但没有找到我的具体问题的解决方案:/ 其思想是只获取与纬度/经度数字序列不匹配的情况 [i for i in [re.findall(r"^\-?[0-9]+\.[0-9]+", string) for string in real_state['latitude']]] 我建议用您的图案拆分字符串: import re s = "Text: 0.1

所以我试图否认这个模式,但它不起作用,即使我用一个简单的例子来概括它。我想这是把它和锚搞混了,但我找不到一个办法来回避这个问题。我检查了其他问题,但没有找到我的具体问题的解决方案:/

其思想是只获取与纬度/经度数字序列不匹配的情况

[i for i in [re.findall(r"^\-?[0-9]+\.[0-9]+", string) for string in real_state['latitude']]]

我建议用您的图案拆分字符串:

import re
s = "Text: 0.12345 and -12.34433 and more to come"
results = re.split(r"\s*-?[0-9]+\.[0-9]+\s*", s)
print(results)

如果出现任何空项,如匹配项出现在字符串的开头/结尾,请使用筛选器将其删除:


请参阅。

您是否还可以包括您的数据看起来像什么、您得到了什么以及您想要什么?我得到了正确的匹配,但是我想要否定,所以我可以找到它不匹配的情况,^不是群构造之外的否定。它表示行的开始。您可能想做的是[i for i in real_state['latitude']如果re.searchr \-?[0-9]+\[0-9]+,我是无,但没有样本数据很难判断。请尝试re.splitr-?[0-9]+\[0-9]+, string@Idlehands这是可行的,但并没有完全解决我的问题。不管怎样,谢谢你这样做,因为在将来它会很有用。过滤器有助于删除re.split生成的空白,所以谢谢你的帮助!
import re
s = "0.12345 and -12.34433 and more to come 0.54321 and -27.87654"
results = re.split(r"\s*-?[0-9]+\.[0-9]+\s*", s)
# print(results)                   # => ['', 'and', 'and more to come', 'and', '']
print(list(filter(None, results))) # => ['and', 'and more to come', 'and']