Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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,我有这个HTTP请求,我只想显示授权部分(base64值):有帮助吗 This Request is stored on a variable called hreq 我试过这个: reg = re.search(r"Authorization:\sBasic\s(.*)\r", hreq) print reg.group() 但是不起作用 请求如下: HTTP Request: Path: /dynaform/custom.js Http-Version: HTTP/1.1 Hos

我有这个HTTP请求,我只想显示授权部分(base64值):有帮助吗

This Request is stored on a variable called hreq 
我试过这个:

reg = re.search(r"Authorization:\sBasic\s(.*)\r", hreq)
print reg.group()
但是不起作用

请求如下:

HTTP Request: 
Path: /dynaform/custom.js 
Http-Version: HTTP/1.1 
Host: 192.168.1.254 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate 
Referer: http://domain.com/userRpm/StatusRpm.htm 
Authorization: Basic YWhtEWa6MDfGcmVlc3R6bGH 

我想显示值YWhtEWa6MDfGcmVlc3R6bGH 求你了,我需要你的帮助
提前感谢专家们

这个
\r
可能是在扔东西;在请求的末尾可能没有回车符(但很难说是从这个结尾)。请尝试将其删除或改用
$
(输入结束)


在将输入放入代码之前,您可以使用此功能手动尝试输入。

如果这是您的全部输入文本,则
/(\b[].*)$/
可能会有所帮助

[]
匹配文本中的空格字符。接

*
任何后跟


$
字符串的结尾

您可以去掉正则表达式结尾的
\r
,在Linux中它是一个
\n
,它可能会破坏您的脚本,因为您期望的是
\r
而不是
\n

>>> reg = re.search(r"Authorization:\sBasic\s(.*)", a)
>>> reg.groups()
('YWhtEWa6MDfGcmVlc3R6bGH ',)
谢谢你的回答:),事实上我得到了一个错误消息

但不管怎样我要展示我到底想做什么

以下是脚本: !/usr/bin/python 从斯卡皮来的,都是进口货*

从scapy.error导入scapy_异常

从scapy导入HTTP

my_iface=“wlan0”

计数=0

def pktTCP(pkt):


嗅探(filter='tcp and port 80',iface=my\u iface,prn=pktTCP)是验证的换行部分吗?如果没有,就把它扔掉。行的开头不使用任何验证,因此。。
global count

count=count+1

if HTTP.HTTPRequest or HTTP.HTTPResponse in pkt:
     src=pkt[IP].src
     srcport=pkt[IP].sport
     dst=pkt[IP].dst
     dstport=pkt[IP].dport
     test=pkt[TCP].payload

     if HTTP.HTTPRequest in pkt:
        print "HTTP Request:"

        print test 
        print "======================================================================"
     if HTTP.HTTPResponse in pkt:
        print "HTTP Response:"
        print test 
        print "======================================================================"