const regex = /(\d[ \-.)]{0,3}){11,20}|(\b[\d]{3}\b)[^,.]/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\d[ \\-.)]{0,3}){11,20}|(\\b[\\d]{3}\\b)[^,.]', 'g')
const str = `1546
4 8 6 2 6 4 1 1 5 3 6 6 6 7 7 1
5378 2052 1163 1153
6011-7614 4775 1364
333 112,55 mdsksajfk
05536080
214
12/05
12/08
122sss 222222222222111 22464 222 222ss, 222,22 22.22 333215122 22 33 123456789012
122.44
445
1546
4 8 6 2 6 4 1 1 5 3 6 6 6 7 7 1
5378 2052 1163 1153
6011-7614 4775 1364
333 112,55 mdsksajfk
11947285580
(11)947285580
1194728-5580
11 94728 5580
346.549.668-32
46254966832
31604523875
10154511,55
12/56/12019`;
// 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