举个例子:
替换前
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://movie.douban.com
Cache-Control: must-revalidate, no-cache, private
Connection: keep-alive
Content-Encoding: br
Content-Type: application/json; charset=utf-8
Date: Tue, 08 Dec 2020 08:12:04 GMT
Expires: Sun, 1 Jan 2006 01:00:00 GMT
Keep-Alive: timeout=30
Pragma: no-cache
Server: dae
Set-Cookie: bid=QfmDsWrTsvE; Expires=Wed, 08-Dec-21 08:12:04 GMT; Domain=.douban.com; Path=/
Strict-Transport-Security: max-age=15552000
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-DAE-App: talion
X-DAE-Instance: default
X-Douban-Mobileapp: 0
X-DOUBAN-NEWBID: QfmDsWrTsvE
X-Xss-Protection: 1; mode=block
下面那么多键值对从 chrome 的 response headerds 复制过去时没有引号,结尾处没有逗号
如果一个一个的加上引号和逗号会比拟麻烦,浪费时间,这样的状况下能够编写个正则表达式进行匹配替换
应用了正则表达式 (.*?): (.*)
匹配了不带引号的键值对, 而 '$1': '$2',
则示意替换成冒号前后要加引号并且结尾处加上逗号的模式, 抉择全副替换,一次性替换成须要的键值对模式,十分不便
上面是 vscode 针对正则表达式的官网链接:
https://docs.microsoft.com/en…