const regex = /jquery-?[0-9.]*(.min|.slim|.slim.min)?\.js/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('jquery-?[0-9.]*(.min|.slim|.slim.min)?\\.js', 'gm')
const str = `https://www.staging2.villageofalamance.com/wp-includes/js/jquery/jquery.min.js
https://www.staging2.villageofalamance.com/wp-includes/js/jquery/jquery.js
https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.js
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js
https://code.jquery.com/jquery-3.5.1.min.js
https://code.jquery.com/jquery-3.5.1.js
https://code.jquery.com/jquery-3.5.1.slim.js
https://code.jquery.com/jquery-3.5.1.slim.min.js
https://c0.wp.com/c/5.2.2/wp-includes/js/jquery/jquery.js
## Shouldn't be excluded
https://www.staging2.villageofalamance.com/wp-content/plugins/league-table/public/assets/js/tablesorter/jquery.tablesorter-min.js?ver=2.08
https://www.staging2.villageofalamance.com/wp-content/themes/bridge/js/plugins/jquery.appear.js?ver=5.6
https://www.staging2.villageofalamance.com/wp-content/themes/bridge/js/plugins/jquery.flexslider-min.js?ver=5.6`;
// 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