const regex = /((|\s|\n)*subnet(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*netmask(|\s|\n)*((\d{1,3}.){3}(\d{1,3}))(|\s|\n)*\{(|\s|\n)+((|\s|\n)+host(|\s|\n)*(\w+)(|\s|\n)*\{(|\s|\n)*(\w*)\:(\w*)\;(|\s|\n)*\}(|\s|\n)*)*\})/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((|\\s|\\n)*subnet(|\\s|\\n)*((\\d{1,3}.){3}(\\d{1,3}))(|\\s|\\n)*netmask(|\\s|\\n)*((\\d{1,3}.){3}(\\d{1,3}))(|\\s|\\n)*\\{(|\\s|\\n)+((|\\s|\\n)+host(|\\s|\\n)*(\\w+)(|\\s|\\n)*\\{(|\\s|\\n)*(\\w*)\\:(\\w*)\\;(|\\s|\\n)*\\}(|\\s|\\n)*)*\\})', '')
const str = `#DHCP Server Configuration file.
deny unknown-clients;
subnet 10.8.140.2 netmask 255.255.255.255 {
host example{
optian:param;
}
host example2{
option2:param2;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
host example{
optian:param;
}
}
subnet 20.8.110.1 netmask 255.255.255.255 {
}`;
// 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