const regex = /(?:(?:.*\n){0,10}).*?Error.*(?:(?:\n.*){0,10})/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:(?:.*\\n){0,10}).*?Error.*(?:(?:\\n.*){0,10})', 'g')
const str = `1
2
3
4
5
6
7
8
9
10
TypeError: Parameter 'url' must be a string, not undefined at Url.parse (url.js:107:11) at urlParse (url.js:101:5) at Object.urlResolve [as resolve] (url.js:404:10) at parseMarkdown (/opt/controllers/api/userguide.js:53:19) at /opt/controllers/api/userguide.js:33:17 at Object. (/opt/models/api.js:172:4) at /opt/lib/data/api.js:138:5 at IncomingMessage. (/opt/node_modules/httpunch/lib/_wrap_request.js:100:9) at IncomingMessage.g (events.js:180:16) at IncomingMessage.emit (events.js:117:20)
1
2
3
4
5
6
7
8
9
10`;
// 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