Text parser for phone numbers (replace, regex)

Hello Makers, I’m trying to extract a (single) phone number from a simple string using replace, but can’t wrap my heard around the required regex value to remove all white space and letter characters from the string. Thanks!

@Zbulo

replace(1.string;/(?:a|[^a])*?(?:^|\s|\()(\d{3})[^\d]{1,2}(\d{3})[^\d](\d{4})(\s|$)(?:a|[^a])*/;$1-$2-$3)

Will extract number a “123-123-1234” phone number from the string. It is very flexible, will let most anything match and does no validation.

If that is not what you want, please give more details.


Jim - The Monday Man (YouTube Channel) Our latest vid: Reading REALLY Large monday Boards
What is Make & How can it help you with monday?
We Create Custom Solutions - Your Make or Ours
Schedule a 1-on-1 Tutorial Session (for monday, Make or “Rocket Science”)

3 Likes

Thanks for your help @JimTheMondayMan

  • Sample string: " Re: +112345678 First Last"
  • Desired result: +112345678 or 112345678

I’m trying to strip the string of everything but the digits (and optionally the plus).

1 Like

@Zbulo

That’s much easier.

replace(1.string;/(?:.*?((?:1\d{8})|(?:\d{8}))(?:\s|$).*)|.*/;$)

Will extract the first 8 contiguous digits or first 9 if the first digit is a 1. Will return nothing if digits are not found. Assumes single line value (no newline characters).

If you want a different number of digits, change the {8}s to the desired number.


Jim - The Monday Man (YouTube Channel) Our latest vid: Reading REALLY Large monday Boards
What is Make & How can it help you with monday?
We Create Custom Solutions - Your Make or Ours
Schedule a 1-on-1 Tutorial Session (for monday, Make or “Rocket Science”)

4 Likes

Hey Jim,

I’m a total newb with regex and trying to use your formula but my desired output is not happening. My goal is to remove a +1 from a phone number.

Example: +14586568888 to 4586568888

I thought your code would work but the output I get is $ symbol.

Here is my formula. The incoming number is from a Twilio watch module
replace(4. From;/(?:.?((?:1\d{8})|(?:\d{8}))(?:\s|$).)|.*/;$)

Any ideas or a better way to do this?

1 Like

I tried this but just returns the number intact with no changes
replace(4. From;‘(\+1)’;‘’)

@Benton_Cotter

First, welcome to Make!

Second, it’s better to post a something like this as a separate, new topic, since this is not directly related to the original post.

But you’re young… to simply remove all occurrences of “+1” from a list of digits (at least 1) proceeded by a white space character (or at the beginning) in a string:
{{replace(4.From​; "/(?<=\s|^)\+1(?=\d+)/g"; emptystring)}}


Jim - The Monday Man (YouTube Channel) Our latest vid: Reading REALLY Large monday Boards
What is Make & How can it help you with monday?
We Create Custom Solutions - Your Make or Ours
Schedule a 1-on-1 Tutorial Session (for monday, Make or “Rocket Science”)

2 Likes

Thanks Jim, Sorry for the #newfail
It worked perfectly. You are the man!! I will for sure do proper etiquette next time. Thanks for the help.

2 Likes

@Benton_Cotter

You’re welcome. No worries.


Jim - The Monday Man (YouTube Channel) Our latest vid: Reading REALLY Large monday Boards - Part 2
What is Make & How can it help you with monday?
We Create Custom Solutions - Your Make or Ours
Schedule a 1-on-1 Tutorial Session (for monday, Make or “Rocket Science”)

1 Like

2 posts were split to a new topic: Changing ‘item data type’ from ‘text’ to ‘number’