Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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/1/list/4.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中匹配字符串序列中的2个单词_Python_Regex - Fatal编程技术网

在Python中匹配字符串序列中的2个单词

在Python中匹配字符串序列中的2个单词,python,regex,Python,Regex,我在Python中有一大组字符串 例如: 我需要选择那些包含https://github.com/和/commit/ 我的代码: 此代码匹配上面示例中的所有4种情况。我需要它只匹配第二个url 我该怎么做 您不能使用和那样的,您需要单独声明: if "https://github.com/" in url and "/commit/" in url: print("OK") else: print("not okay") (x和y)在z中到x在z中,y在z中。您能提供更多详细信

我在Python中有一大组字符串

例如:

我需要选择那些包含
https://github.com/
/commit/

我的代码:

此代码匹配上面示例中的所有4种情况。我需要它只匹配第二个url


我该怎么做

您不能使用
和那样的
,您需要单独声明:

if "https://github.com/" in url and "/commit/" in url:
    print("OK")
else:
    print("not okay")

(x和y)在z中
x在z中,y在z中
。您能提供更多详细信息吗
if ("https://github.com/" and "/commit/") in url:
        print("OK")
else:
        print("not okay")
if "https://github.com/" in url and "/commit/" in url:
    print("OK")
else:
    print("not okay")