假如有这么个文本,想匹配出所有的请求头:
curl 'http://localhost:8088/api/ac/b/e' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: zh-CN,zh;q=0.9' \
-H 'Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiLlm73nlLXnlLXlipsiLCJpcCI6IjEyNy4wLjAuMSIsImV4cCI6MTY2MjAxNDk5NCwidXNlcklkIjoiNzBhMTAxNjk2ZDhlNGZmNjgzMzhiZTYzZmE1YjIxOTYifQ.XdWxH6Py6Yk4cc-F0U8u3JBEhta0ctWqK-0eXRFNnuayG9jgclqDjratY_18JGSHP9v-69e-3y_2k-W056bd4G6LMS19JdULfulSjIuOzhIDi0bF44dlkUyqQ_qtjT2rrKTTOnM8OHPpgAlEIdyO4fyImbyDe6eMn1ldjD0YsEM' \
-H 'Connection: keep-alive' \
-H 'Cookie: acw_tc=2760820216620004799778577eb46126378b067280bcc79c20e143b0c22d26; vue_admin_template_token=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiLlm73nlLXnlLXlipsiLCJpcCI6IjIxOC4xOS4yNy40MCwgMzkuOTYuMTMwLjIiLCJleHAiOjE2NjIwMDIyODQsInVzZXJJZCI6IjcwYTEwMTY5NmQ4ZTRmZjY4MzM4YmU2M2ZhNWIyMTk2In0.eWZh6EGafQjQNSUANCEQI_-6Am1aBLhFAzwGWoTraCwjvkDnPbF9cFtiDCW5X5ZYB-tIncPlTyXX-Nz32spg2u74sDj14lsAiUHl3hni_AE9-gJr1kyuVQZyBx48oupWuqnltjcJdZwwQyaIcUw33nN7MZ86inwTyIdEeW2rwrM' \
-H 'Referer: https://ta.com/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Windows"' \
--compressed
代码实现:
- let reg = /-H '(.*): (.*)'/g;
- let res;
- while (res = reg.exec(this.curlRequest)) {
- console.log(res[1] + ":" + res[2]);
- }
输出: