I am trying to extract *phone numbers* from a web page using Python & RegEx

**Australian number format** 

+61 (international code - shown below as 'i') 

02, 03, 07 or 08 (state codes - shown below as 's')

1234-5678 (8 digit local number - shown below as 'x')

**Common variations of format** (in order of commonality):

Format 1: ss xxxx xxxx (e.g. 02 1234 5678)

Format 2: +ii s xxxx xxxx (e.g. +61 2 1234 5678) (note the first 's' digit is removed here)

Format 3: (seen rarely) +ii (s)s xxxx-xxxx (e.g. +61 (0)2 1234 5678

**My RegEx**:

```
re.findall(r'[0][2]\d{8}|[0][3]\d{8}|[0][7]\d{8}|[0][8]\d{8}|[6][1][2]\d{8}|[6][1][3]\d{8}|[6][1][7]\d{8}|[6][1][8]\d{8}|[0][4]\d{8}|[6][1][4]\d{8}|[1][3][0][0]\d{6}|[1][8][0][0]\d{6}', re.sub(r'\W+', '', sample_text))

```

works well on a simple sample\_text:

> 
> sample\_text =
>  "610212345678ABC##610312345678ABC##610712345678ABC##610812345678ABC##0212345678ABC##0312345678ABC##0712345678ABC##0812345678ABC##61212345678ABC##61312345678ABC##61712345678ABC##61812345678ABC##0412345678ABC##61412345678ABC##130012345678ABC##180012345678ABC##"
> 
> 
> 

Result:

> 
> ['0212345678', '0312345678', '0712345678', '0812345678', 
>  '0212345678', '0312345678', '0712345678', '0812345678', 
>  '61212345678', '61312345678', '61712345678', '61812345678', 
>  '0412345678', '61412345678', '1300123456', '1800123456']
> 
> 
> 

**The Goal**

Using <http://www.outware.com.au/contact> as an example ...

The 2 actual numbers on the page are:

+61 (0)3 8684 9912 and +61 (0)2 8064 7043 (both numbers appear twice - once in the main section of the page and once in the footer)

**The Problem**

```
#take HTML markup from body tags
b = driver.find_element_by_css_selector('body').text

#remove all non-alpha + white space.
b = re.sub(r'\W+', '', b)

```

Result:

> 
> "PORTFOLIOINNOVATIONSERVICESCAREERSINSIGHTSNEWSABOUTCONTACTCONTACTOUTWAREMelbourneLe......AFRFast100Nov92017EXPLOREOUTWAREPortfolioInnovationWorkingatOutwareAboutSitemapCONNECTMELBOURNELevel3469LaTrobeStMelbourneVIC3000610386849912SYDNEYLevel41SmailStUltimoNSW2007610280647043"
> 
> 
> 

Now if I apply my regex to this string

```
re.findall(r'[0][2]\d{8}|[0][3]\d{8}|[0][7]\d{8}|[0][8]\d{8}|[6][1][2]\d{8}|[6][1][3]\d{8}|[6][1][7]\d{8}|[6][1][8]\d{8}|[0][4]\d{8}|[6][1][4]\d{8}|[1][3][0][0]\d{6}|[1][8][0][0]\d{6}', re.sub(r'\W+', '', b))

```

Result:

[u'0386849912', u'0761028064', u'0386849912', u'0761028064']

I am getting a false positive because I have concatenated a postcode "NSW2007" onto the start of the phone number.

I presume because the regex has parsed the first part of "NSW2007610280647043" matching "0761028064" it doesn't then match "0280647043" which is also part of the same substring

I actually don't mind the false positive (i.e. getting "0761028064") but I do need to solve the false negative (i.e. not getting "0280647043")

I know there's some RegEx gurus here who can help on this. :-)

Please help!!