1

I need to extract two phone numbers from a string with delimiters (tilde). The tricky part is the format of the phone numbers can vary.

The string pattern stays the same. But the formatting of the phone numbers can be one of three types

(1)  4 digit extensions. (ex. 1001)
(2) 10 digit (5551112222)
(3) 10 digit with country code (+15558889999)

I need the extension or 10 digit number with the +1 country code stripped off. So

(1) 1001 = 1001
(2) 5551112222 = 5551112222
(3) +15558889999 = 5558889999

Example String

2019/02/06/2019-02-06T084903~call~5551112222~+15558889999~231a6a62-c1c8-43a8-ac2e-f8428237385c.WAV

From the string above, I need to extract two phone numbers with correct 10 digit formatting

(1) 5551112222
(2) 5558889999

So far, I have the following regex expression:

(?<=\~)(.*?)(?=\~)

This gives me three groups

(1) Call
(2) 5551112222
(3) +15558889999

But, what I need is two groups with correct formatting

(1) 5551112222
(2) 5558889999

I'm using this regex pattern with Integromat so no coding language solutions will work in this case. It must be 100% regex.

Appreciate any help on this. Thanks!

0

1 Answer 1

1

You may use

(?<=~\+|~)([0-9]+)(?=~)

See the regex demo

If there is a problem with lookbehind, use a bit modified variant:

(?:(?<=~\+)|(?<=~))([0-9]+)(?=~)

Details

  • (?<=~\+|~) - there must be ~+ or ~ immediately to the left of the current location
  • ([0-9]+) - Group 1: one or more digits
  • (?=~) - there must be ~ immediately to the right of the current location.
Sign up to request clarification or add additional context in comments.

1 Comment

Wiktor, thank you! This works perfectly. I modified slightly to drop the country code as well, since I only want the 10 digit number. (?<=~\+1|~)([0-9]+)(?=~)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.