Need help in writing Regex code

Hi All,
i’m getting an input excel in that i’m having mobile numbers from different countries i want to extract mobile number without country code. I tried few codes on my own but i’m able to do for few, i’m unable to write regex code for all. can anyone help me on this.

+6282 143 761 999
+614098234540
+351 936 180 143
+39 345 888 1948
+61 6149898949
+1 12156121212
+62 0120 999 444
+1 (142) 000-2020
+61 0101 004 777
+1 (901) 123-6969
+12 6 40 01 02 03
+39 430 125 1987
+436776564698
+965 62221111
+1 (522) 666 1043
+39 369 126 9000
+1 1514880339
+61 0441 897 666
+61 0412 004 071
+1 (606) 123-6969
+33 6 10 69 69 60
+39 300 345 6069
+439766969990
+91 (123) 456-7890
18005551234
1 800 555 1234
+1 800 555-1234
+86 800 555 1234
1-800-555-1234
1 (800) 555-1234
(800)555-1234
(800) 555-1234
(800)5551234
800-555-1234
800.555.1234
(003) 555-1212

only some have country code but some dont have , if it have all are same for format you can do with regex

Hi @Veera_Raj as of now let’s try for with country code one

Hi @Learner007,

You can try using this. Additional work can be done for those who cannot be taken.

(\+\d{1,3}\s?)?((\(\d{3}\)\s?)|(\d{3})(\s|-?))(\d{3}(\s|-?))(\d{4})(\s?(([E|e]xt[:|.|]?)|x|X)(\s?\d+))?

Regards,
MY

1 Like

Hi,

Can you try the following sample? This returns country code and phone number properly except
18005551234 because we cannot identify country code is 1 or 18. (However, we can estimate it’s 1 (US)… )

mc = System.Text.RegularExpressions.Regex.Matches(yourString,"^(?<COUNTRYCODE>\+\d{1,2}|\d{1,2}(?=\W))?[-\s]*(?<PHONENUMBER>.+)",System.Text.RegularExpressions.RegexOptions.Multiline)

Sample20220801-1.zip (3.4 KB)

Regards,

2 Likes

Hi @muhammedyuzuak i tried this few it is skipping but worked for most. Thanks for the code.

Thanks @Yoichi This is working perfectly. Thank you so much.

1 Like