Matt Hough
Matt Hough

Reputation: 1099

Regex: Select phone number surrounded by other numbers

I'm trying to select with regex the (fake) phone number in the code below. Sometimes, the phone number has spaces and sometimes it doesn't. Obviously, I want to avoid selecting the other numbers, and I would also like to avoid the + symbol.

Any help would be greatly appreciated.

Example 1:

Test Meeting 
Mon, Jan 8, 2018 5:00 PM - 5:30 PM AEDT 

Please join my meeting from your computer, tablet or smartphone. 
https://example.com/join/132124483

You can also dial in using your phone. 
Australia: +61 2 3017 3203

Access Code: 132-124-483 

First meeting? Let's do a quick system check: https://link.example.com/system-check 

Example 2:

Conference link and details to come. 
──────────────────────────────────────────
Please join my meeting from your computer, tablet or smartphone.
https://example.com/join/829203911

You can also dial in using your phone.
Singapore (Toll Free): 18007932321

Access Code: 829-203-911

First GoToMeeting? Try a test session: https://care.example.com/g2m/getready
──────────────────────────────────────────

Upvotes: 0

Views: 47

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89567

Without all informations, I suggest this pattern:

: \+?\K\d+(?: \d+)*$

Perhaps it is better to add an exhaustive list of countries in an alternation anchored to the start of the line before. It depends of your requirements. Something like this:

^(?:Argentine|France|Singapoure)\b[^\n\r:]*: \+?\K\d+(?: \d+)*$

(all on the left of \K isn't in the whole match result).

Upvotes: 1

Related Questions