const regex = /^.*\bgetHouseName:\h+(.+)(?:\R(?!.*price).*)*\R.*price\h+\(in doll\)\h+\[min:\h+(\d+),\h+max:\h+(\d+)\](?:\R(?!.*squaremtr).*)*\R.*squaremtr\h+\(in doll\)\h+\[min: (\d+),\h+max:(\d+)\](?:\R(?!.*sellVal).*)*\R.*sellVal\h+\(in doll\)\h+\[min:\h+(\d+),\h+max:\h+(\d+)\](?:\R(?!.*rentPrice).*)*\R.*rentPrice\(in doll\)\h+\[min: (\d+),\h+max:\h+(\d+)\]
/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^.*\\bgetHouseName:\\h+(.+)(?:\\R(?!.*price).*)*\\R.*price\\h+\\(in doll\\)\\h+\\[min:\\h+(\\d+),\\h+max:\\h+(\\d+)\\](?:\\R(?!.*squaremtr).*)*\\R.*squaremtr\\h+\\(in doll\\)\\h+\\[min: (\\d+),\\h+max:(\\d+)\\](?:\\R(?!.*sellVal).*)*\\R.*sellVal\\h+\\(in doll\\)\\h+\\[min:\\h+(\\d+),\\h+max:\\h+(\\d+)\\](?:\\R(?!.*rentPrice).*)*\\R.*rentPrice\\(in doll\\)\\h+\\[min: (\\d+),\\h+max:\\h+(\\d+)\\]
', 'gm')
const str = `[04:04:04s] [startedRetrieving]getHouseName: house1
[04:04:04s] [startedRetrieving]random useless text
[04:04:04s] [startedRetrieving]price (in doll) [min: 1000, max: 1200]
[04:04:05s] [startedRetrieving]squaremtr (in doll) [min: 75, max:85]
[04:04:04s] [startedRetrieving]sellVal (in doll) [min: 1000, max: 1200]
[04:04:05s] [startedRetrieving]random useless text
[04:04:05s] [startedRetrieving]random useless text
[04:04:05s] [startedRetrieving]random useless text
[04:04:05s] [startedRetrieving]rentPrice(in doll) [min: 150, max: 200]
[04:06:04s] [startedRetrieving]getHouseName: house2
[04:06:04s] [startedRetrieving]price(in doll) [min: 1004, max 1100]
[04:06:04s] [startedRetrieving]squaremtr(in doll) [min: 85, max 99]
[04:06:04s] [startedRetrieving]sellVal(in doll) [min: 950, max: 1050]
[04:06:04s] [startedRetrieving]random useless text
[04:06:04s] [startedRetrieving]rentPrice(in doll) [min: 150, max: 290]
[04:09:04s] [startedRetrieving]getHouseName: house3
[04:09:04s] [startedRetrieving]price(in doll) [min: 1099, max: 1200]
[04:09:04s] [startedRetrieving]squaremtr(in doll) [min: 90, max: 110]
[04:09:04s] [startedRetrieving]random useless text
[04:09:04s] [startedRetrieving]random useless text
[04:09:04s] [startedRetrieving]sellVal(in doll) [min: 1100, max: 1300]
[04:09:04s] [startedRetrieving]random useless text
[04:09:04s] [startedRetrieving]rentPrice(in doll) [min: 199, max: 300]`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// 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