const regex = /timeout\shttp-request\s+\d+(?=[\s\S]+defaults)/m;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('timeout\\shttp-request\\s+\\d+(?=[\\s\\S]+defaults)', 'm')
const str = `global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 32768
tune.maxaccept -1
chroot /var/lib/haproxy
daemon
timeout http-request 5000
stats socket /var/run/haproxy.sock mode 600 level admin
stats timeout 2m
defaults
log global
mode http
option httplog
option dontlognull
retries 5
option redispatch
maxconn 16384
timeout connect 7s
timeout client 500s
timeout server 500s
timeout http-request 7000
timeout client-fin 30s
timeout tunnel 1h`;
// 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