const regex = new RegExp('[a-zA-Z0-9\\-\\_]*\\.[a-zA-Z0-9\\-\\_]*\\.\\w{1,3}(\\.\\w{1,3})?', 'gm')
const str = `
service.mensfitness.co.uk
updates.mensfitness.co.uk
promo.mensfitness.co.uk
deals.mensfitness.co.uk
subs.mensfitness.co.uk
service.healthandfitnessoneline.co.uk
updates.healthandfitnessoneline.co.uk
promo.healthandfitnessoneline.co.uk
deals.healthandfitnessoneline.co.uk
subs.healthandfitnessoneline.co.uk
service.custompc.co.uk
updates.custompc.co.uk
promo.custompc.co.uk
deals.custompc.co.uk
subs.custompc.co.uk
service.digitalslrphoto.com
updates.digitalslrphoto.com
promo.digitalslrphoto.com
deals.digitalslrphoto.com
subs.digitalslrphoto.com
`;
const subst = `'\g<0>'`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
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