const regex = /^(-?(?=\d{1,15}(?:[.,]0+)?0*$|(?:(?=[,.\d]{1,16}0*$)(?:\d+[.,]\d{1,2}$))).{1,16}).*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(-?(?=\\d{1,15}(?:[.,]0+)?0*$|(?:(?=[,.\\d]{1,16}0*$)(?:\\d+[.,]\\d{1,2}$))).{1,16}).*$', 'gm')
const str = `// PASS
0
0.12
1
-1
1.23456789012345
10.2345678901234
12.3456789012345
-123.4
-12.34
-1,33
-1.33
-1.333
-1234567.12
-1234567890123450
-12345678901234.50
12345678901234.50
123456789012345.00
// FAIL
-1234567890123456
-12345678901234.56
12345678901234.56
123456789012345.60
1.234567890123456
12.34567890123456
123456789012340.6
123456789012300.67
123456789012300000000000.67
10000000000010000000001000010000000001.22`;
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