Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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,文本没有空格,所以我根本无法拆分并对字符串列表使用索引 我正在寻找的模式是: check= 它后面是一个数字和编码的querystring项(apachelogfile),并且在文件的每一行上出现两次。我想要的输出只提供以下内容check= 例如,行中的字符串如下所示: 11.249.222.103 - - [15/Aug/2016:13:17:56 -0600] "GET /next2/120005079807?check=37593467%2CCOB&check=37593378%2

文本没有空格,所以我根本无法拆分并对字符串列表使用索引

我正在寻找的模式是:

check=

它后面是一个数字和编码的querystring项(apachelogfile),并且在文件的每一行上出现两次。我想要的输出只提供以下内容
check=

例如,行中的字符串如下所示:

11.249.222.103 - - [15/Aug/2016:13:17:56 -0600] "GET /next2/120005079807?check=37593467%2CCOB&check=37593378%2CUAP&box=match&submit=Next HTTP/1.1" 500 1633 "https://mvt.squaretwofinancial.com/newmed/?button=All&submit=Submit" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"

在这种情况下,我需要取
37593467
37593378

请检查此代码

import re

text = '''11.249.222.103 - - [15/Aug/2016:13:17:56 -0600] "GET /next2/120005079807?check=37593467%2CCOB&check=37593378%2CUAP&box=match&submit=Next HTTP/1.1" 500 1633 "https://mvt.squaretwofinancial.com/newmed/?button=All&submit=Submit" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"'''


for match in re.findall("check=(\d+)",text):
    print 'Found "%s"' % match
输出:

C:\Users\dinesh_pundkar\Desktop>python demo.py
Found "37593467"
Found "37593378"
两个URL以获取帮助:


请检查此代码

import re

text = '''11.249.222.103 - - [15/Aug/2016:13:17:56 -0600] "GET /next2/120005079807?check=37593467%2CCOB&check=37593378%2CUAP&box=match&submit=Next HTTP/1.1" 500 1633 "https://mvt.squaretwofinancial.com/newmed/?button=All&submit=Submit" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"'''


for match in re.findall("check=(\d+)",text):
    print 'Found "%s"' % match
输出:

C:\Users\dinesh_pundkar\Desktop>python demo.py
Found "37593467"
Found "37593378"
两个URL以获取帮助:


  • re.findall(r')(?
    re.findall(r'(?好的,要修改,我如何在…之后的文本上搜索,即,我如何获得匹配项以根据是否找到
    %2CCOB
    %2CUAP
    ?好的,要修改,我如何在…之后的文本上搜索,即,我如何获得匹配项以根据是否找到
    %2CCOB
    %2CUAP显示数字e> ??