const regex = new RegExp('^\\(?(?P<prefix>(?=1)|\\+|(?:0(?:0(?:0|1|9)?|1(?:0|1))?|119))[-. ]?\\(?(?P<CC>1([-. ]?)[0-9]{3}|2(?:0|[0-9]{2})|3(?:[0-469]|[0-9]{2})|4(?:[013-9]|[0-9]{2})|5(?:[1-8]|[0-9]{2})|6(?:[0-6]|[0-9]{2})|7(?:[-. ]?[67]|[0-9]{3})|8(?:[1246]|[0-9]{2})|9(?:[0-58]|[0-9]{2}))(?:\\)?[-. ])?(?P<number>(?:[0-9]+[-. ]?)+)$', 'mg')
const str = `#phone number testing
001 37156
(+213) 44
00 1-684 11
000 376 124
+244 111
+1-264 111
010-672-11
1-268 1111111
+44-111
44-111
+1-719-691-8965
1-719-691-8965
+1719-691-8965
1719-691-8965
17196918965
1.719.691.8965
1 719 691 8965
0021222
0011222
0011222
+401111
+4241111
+5111
+3716888
+36898989
1-803-974-0876
1-688-944-7218
1-945-925-9015
1-644-486-1985
1-949-959-6957
1-989-134-4495
1-789-437-5612
1-759-923-2805
1-108-433-5627
(656) 322-0032
(318) 842-1324
(108) 803-8302
(638) 621-0848
(258) 568-2801
(423) 453 2131
(372) 785.2492
(189) 151 8444
(339) 570.2367
(640) 308-3953
+561111
+374
+297
+247
+61
+672
+43
+994
+1-242
+973
+880
+1-246
+1-268
+375
+32
+501
+229
+1-441
+975
+591
+387
+267
+55
+1-284
+673
+359
+226
+257
+855
+237
+1
+238
+1-345
+236
+235
+64
+56
+86
+53
+61
+57
+269
+242
+243
+682
+506
+225
+385
+53
+5399
+599
+357
+420
+45
+246
+253
+1-767
+1-809
1-829
+670
+56
+593
+20
+503
+8812
+8813
+88213
+240
+291
+372
+251
+500
+298
+679
+358
+33
+596
+594
+689
+241
+220
+995
+49
+233
+350
+881
+30
+299
+1-473
+590
+1-671
+5399
+502
+245
+224
+592
+509
+504
+852
+36
+354
+91
+62
+871
+874
+873
+872
+870
+800
+808
+98
+964
+353
+8816
+8817
+972
+39
+1-876
+81
+962
+7
+254
+686
+850
+82
+965
+996
+856
+371
+961
+266
+231
+218
+423
+370
+352
+853
+389
+261
+265
+60
+960
+223
+356
+692
+596
+222
+230
+269
+52
+691
+1-808
+373
+377
+976
+382
+1-664
+212
+258
+95
+264
+674
+977
+31
+599
+1-869
+687
+64
+505
+227
+234
+683
+672
+1-670
+1-1
+47
+968
+92
+680
+970
+507
+675
+595
+51
+63
+48
+351
++1-787 or +1-939
+974
+262
+40
+7
+250
+290
+1-869
+1-758
+508
+1-784
+685
+378
+239
+966
+221
+381
+248
+232
+65
+421
+386
+677
+252
+27
+34
+94
+249
+597
+268
+46
+41
+963
+886
+992
+255
+66
+88216
+670
+228
+690
+676
+1-868
+216
+90
+993
+1-649
+688
+256
+380
+971
+44
+1
+1-340
+878
+598
+998
+678
++39, +379
+58
+84
+808
+681
+967
+260
+255
+263
`;
// 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