const regex = /(?s)(?:.*?May 2016){3}\K.*?(?=Jun 2016)/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?s)(?:.*?May 2016){3}\\K.*?(?=Jun 2016)', '')
const str = `May 2016 ef Jun 2016 efef May 2016 Jun 2016 May 2016
dffdg def efef
Jun 2016
May 2016
Jun 2016
foo bar
`;
// 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