const regex = /^(get|post|head|options|put|delete|trace|connect) [\x09-\x0d -~]*? http\/(0\.9|1\.0|1\.1)|^http\/(0\.9|1\.0|1\.1) [1-5][0-9][0-9]/si;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(get|post|head|options|put|delete|trace|connect) [\\x09-\\x0d -~]*? http\\\/(0\\.9|1\\.0|1\\.1)|^http\\\/(0\\.9|1\\.0|1\\.1) [1-5][0-9][0-9]', 'si')
const str = `HTTP/1.1 206 Partial Content
Server: nginx
Date: Wed, 11 Nov 2015 03:56:37 GMT
Content-Type: application/octet-stream
Content-Length: 356602
Last-Modified: Sat, 09 May 2015 01:02:03 GMT
Connection: keep-alive
Cache-Control: no-store
Pragma: no-cache
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: X-TCP-Info,X-Session-Info
X-TCP-Info: h0=1468775468;h1=1393591241;h2=2806702307;h3=4238532199;h4=1088413687;
X-Session-Info: addr=14.203.114.166;port=64848;argp=6.r_LuFhNjxnyyv1lFwH73LPg5P97q98pNwisQ1a9GcfM
Content-Range: bytes 221217390-221573991/345312900
...{moof....mfhd...........ctraf....tfhd... ............tfdt.......
.tj\`...Asaiz........0....................................`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions