const regex = new RegExp('((\\+|\\+\\s|\\d{1}\\s?|\\()(\\d\\)?\\s?[-\\.\\s\\(]??){8,}\\d{1}|\\d{3}[-\\.\\s]??\\d{3}[-\\.\\s]??\\d{4}|\\(\\d{3}\\)\\s*\\d{3}[-\\.\\s]??\\d{4}|\\d{3}[-\\.\\s]??\\d{4})', 'mg')
const str = ` +61 2 8249 5000
+61 2 6122 5100
+61 2-9407 5247
+65-8233-6124
+61 412 364 923
1300 890 902
0435 569 072
8801911384785
0086-010-58732690
+ 852 2118 3893
(852) 2513 3168
(852) 2865-9898
+91-9552503220
+914042024714
+919948298078
+91 22 25094755
0124 4742300
+1 (972)273 0738
08111 90 1859
+62-21-5201214
+62 21 2995 1641
603-4270 2309
+603 7724 1199
+603-77108288
+632 8937377
(65) 6723 6888
+6596233196
+656379 2681
+65 6737 0324
82-70-7791-7100
+82 17 238 1226
82-31-478-4506
+822-6309-6366
(000)000-0000
(000)000 0000
(000)000.0000
(000) 000-0000
(000) 000 0000
(000) 000.0000
0000000000
(000)0000000
(000)000-0000
(000)000 0000
(000)000.0000
(000) 000-0000
(000) 000 0000
(000) 000.0000
000-0000
000 0000
000.0000
0000000
0000000000
(000)0000000`;
// 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