您好,登錄后才能下訂單哦!
這篇文章主要介紹正則如何給header的冒號(hào)兩邊參數(shù)添加單引號(hào),文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
正則給header的冒號(hào)兩邊參數(shù)添加單引號(hào)(Python請(qǐng)求用)
直接從瀏覽器Chrome復(fù)制header值如下:
Host: kyfw.12306.cn Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Accept: */* X-Requested-With: XMLHttpRequest If-Modified-Since: 0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 Referer: https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%E4%B8%8A%E6%B5%B7,SHH&ts=%E9%A6%99%E6%B8%AF%E8%A5%BF%E4%B9%9D%E9%BE%99,XJA&date=2019-04-12&flag=N,N,Y Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 Cookie: JSESSIONID=76B27521A27493046570C27D4EA89116; RAIL_OkLJUJ=FFA0Gp4TGPWRINmcFUWWyIHH0ugtMppg; _jc_save_wfdc_flag=dc; ten_key=ySPk59Ew/hagxMnD31qdYQ64ryEVBMwd; ten_js_key=ySPk59Ew%2FhagxMnD31qdYQ64ryEVBMwd; BIGipServerotn=1123025418.64545.0000; RAIL_EXPIRATION=1555320982648; RAIL_DEVICEID=SandqZ9YRixyZOnJ2ZMUl2iYN8RPrDz8F6WsV6wDEryAZh_41c-qHzPyRmNlJNXpOSoNpmYE3SIpEhKVV06mAxHwB6RWk-l4vxZg0an4qePt-qPsrnaceVrdc7eZzC1dJheS9V9TYLwrGQ_iG85ax_hB8VADhhu3; BIGipServerpool_passport=200081930.50215.0000; route=c5c62a339e7744272a54643b3be5bf64; _jc_save_fromStation=%u4E0A%u6D77%2CSHH; _jc_save_toDate=2019-04-12; BIGipServerportal=2949906698.17695.0000; _jc_save_toStation=%u5357%u5B81%2CNNZ; _jc_save_fromDate=2019-04-30
用正則表達(dá)式替換后的如下:(正則替換后再手動(dòng)去掉最后一行最后一個(gè)逗號(hào))
'Host':' kyfw.12306.cn', 'Connection':' keep-alive', 'Pragma':' no-cache', 'Cache-Control':' no-cache', 'Accept':' */*', 'X-Requested-With':' XMLHttpRequest', 'If-Modified-Since':' 0', 'User-Agent':' Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36', 'Referer':' https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%E4%B8%8A%E6%B5%B7,SHH&ts=%E9%A6%99%E6%B8%AF%E8%A5%BF%E4%B9%9D%E9%BE%99,XJA&date=2019-04-12&flag=N,N,Y', 'Accept-Encoding':' gzip, deflate, br', 'Accept-Language':' zh-CN,zh;q=0.9', 'Cookie':' JSESSIONID=76B27521A27493046570C27D4EA89116; RAIL_OkLJUJ=FFA0Gp4TGPWRINmcFUWWyIHH0ugtMppg; _jc_save_wfdc_flag=dc; ten_key=ySPk59Ew/hagxMnD31qdYQ64ryEVBMwd; ten_js_key=ySPk59Ew%2FhagxMnD31qdYQ64ryEVBMwd; BIGipServerotn=1123025418.64545.0000; RAIL_EXPIRATION=1555320982648; RAIL_DEVICEID=SandqZ9YRixyZOnJ2ZMUl2iYN8RPrDz8F6WsV6wDEryAZh_41c-qHzPyRmNlJNXpOSoNpmYE3SIpEhKVV06mAxHwB6RWk-l4vxZg0an4qePt-qPsrnaceVrdc7eZzC1dJheS9V9TYLwrGQ_iG85ax_hB8VADhhu3; BIGipServerpool_passport=200081930.50215.0000; route=c5c62a339e7744272a54643b3be5bf64; _jc_save_fromStation=%u4E0A%u6D77%2CSHH; _jc_save_toDate=2019-04-12; BIGipServerportal=2949906698.17695.0000; _jc_save_toStation=%u5357%u5B81%2CNNZ; _jc_save_fromDate=2019-04-30'
find匹配:(.*?)\:(.*?)\n
replace替換:'$1':'$2',\n
sublime如下:
匹配效果如下:
以上是“正則如何給header的冒號(hào)兩邊參數(shù)添加單引號(hào)”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。