Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 - Fatal编程技术网

Python 正则表达式-不包括单词,但带有通配符

Python 正则表达式-不包括单词,但带有通配符,python,regex,Python,Regex,用一个表达式可能不太可能,但这里是 txt = 'check from HERE and i need RED but not BLUE' 对于上面的文本,我需要一个表达式,如果在“HERE”之后的任何地方出现“RED”,而在“HERE”之后的任何地方不出现“BLUE”,则该表达式将匹配。对于后代: 没有正则表达式 正则表达式 看看负面表情:@user3080953,我找到了我需要的。问题解决了。谢谢。@TokyoD请在那里为将来的其他人发布答案。对于您的第一个选项,如果这里有多个,?只能使用

用一个表达式可能不太可能,但这里是

txt = 'check from HERE and i need RED but not BLUE'
对于上面的文本,我需要一个表达式,如果在“HERE”之后的任何地方出现“RED”,而在“HERE”之后的任何地方不出现“BLUE”,则该表达式将匹配。

对于后代:

没有正则表达式 正则表达式
看看负面表情:@user3080953,我找到了我需要的。问题解决了。谢谢。@TokyoD请在那里为将来的其他人发布答案。对于您的第一个选项,如果这里有多个
?只能使用
txt.split('HERE',1)
拆分一次。
txt = 'check from HERE and i need RED but not BLUE'
after_here = txt.split('HERE', 1)[1]
result = red in after_here and blue not in after_here
^.*HERE(?!.*BLUE.*).*RED.*$
#   ^ look after 'HERE'
#           ^ negative lookahead in everything that comes after HEAD for BLUE
#                     ^ look for RED in everything that comes after HEAD

// see https://www.regular-expressions.info/lookaround2.html