const regex = /(?'group1'[\d])/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?\'group1\'[\\d])', 'gm')
const str = `101011010
110101101
111010110
111101011
011110101
101111010
110111101
011011110
001101111
100110111
110011011
111001101
111100110
011110011
001111001
100111100
010011110
001001111
100100111
010010011
001001001
000100100
000010010
000001001
000000100
000000010
100000001`;
const subst = `$1 & `;
// 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