const regex = /(.js\b|.css\b)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(.js\\b|.css\\b)', 'g')
const str = `/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/composer.json
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/advanced-visitor-conditions/inc/conditions.js
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/advanced-visitor-conditions/inc/conditions.min.js
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/cache-busting/inc/base.js
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/cache-busting/inc/base.min.js
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/cache-busting/inc/htmlParser.js
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/cache-busting/inc/postscribe.js
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/flash/inc/flash.css
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/modules/flash/inc/flash.js
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/vendor/composer/installed.json
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/vendor/composer/installers/composer.json
/srv/www/admanager/htdocs/wp-content/plugins/advanced-ads-pro/vendor/xrstf/composer-php52/composer.json`;
// 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