Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find phone numbers with a missing 0

I have a csv file opened in Notepad++ and try to use the Search/Replace function with "Regular Expression" checked to find phone numbers with a missing 0.

I have started my regular expression as (\d[0-9]{10}) which finds all phone numbers, but I just need to find those with a missing leading 0.

What is the appropriate RegEx pattern to do this, please?


Test data of the csv file:

ID,TITLE,FNAME,SNAME,GENDER,PHONE,MOBILE,DOB,
1,Mrs,Sue,Mac,Female,01702 11000,07961111111,23/4/1958 
01,Mrs,Sue,Mac,Female,1702 11000,07961111111,23/4/1958 
2,Mr,Jim,Bell,Male,01698502269,07961111111,5/5/1958 
3,Mr,John,Smith,Male,,,,,,,,17/5/1958 00:00:00
4,,Batman,Smith,,,,,,,01389 111 111,07961111111,29/5/1958      
04,,Batman,Smith,,,,,,,1389 111 111,07961111111,29/5/1958      
5,Mr.,Hulk,Smith,Male,01389 111 111,07961111111,2/6/1958 
6,Mr.,Hulk,Briggs,Male,21,07961111111,6/6/1958 
06,Mr.,Hulk,Briggs,Male,21,7961111111,6/6/1958 
7,Mr.,Mike,Brigs,Male,15-20,07961111111,6/6/1958 
8,Mr.,Mike,Briggs,Female,20,07961111111,6/6/1958 
9,Mr,David,Golden,Male, 01254 111111,07961111111,10/6/1958
10,Mr,Pete,Lee,Male,020 7111 1111,07961111111,22/6/1958 
11,Ms,Karren,Lee,Female,02881111111,07961111111,4/7/1958 
12,Ms,Lisa,Bond,Female,,,,,,01411111100,07961111111,16/7/1958 
13,Mr,Murdasa,Smith,Male,01268 000 000,07961111111,20/7/1958 
14,,Brian,Smith,,(0)1753 604000,07961111111,24/7/1958 
15,,Brian,Smith,,12 (0)1753 604000,07961111111,24/8/1958 
015,,Brian,Smith,,12 ()1753 604000,07961111111,24/8/1958 
like image 756
Riaz Ladhani Avatar asked Dec 06 '25 11:12

Riaz Ladhani


2 Answers

You should replace \d (any digit) with [1-9] (any digit but 0).

If I got you right, the RegEx pattern you need is: \b([1-9](\d *){9})\b, you can adjust the {9} to {8,10}, depending on the desired phone number length.

http://i.imgur.com/6MHprAW.png


EDIT: Added word boundaries (\b) and let the pattern ignore inbound whitespaces

like image 66
Binkan Salaryman Avatar answered Dec 08 '25 01:12

Binkan Salaryman


Looks like you need to match even fewer than 11 symbols. You can use (?<=,)\b[1-9][0-9 ]{3}[ 0-9]{6,} regex to get your phone numbers.

These lines are matched:

  • 01,Mrs,Sue,Mac,Female,1702 11000,07961111111,23/4/1958
  • 04,,Batman,Smith,,,,,,,1389 111 111,07961111111,29/5/1958
  • 06,Mr.,Hulk,Briggs,Male,21,7961111111,6/6/1958
like image 24
Wiktor Stribiżew Avatar answered Dec 08 '25 01:12

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!