Find & Copy/Cut variable number string in line of text

In the following string of text:
fr 1026a- Kathy Chester 201 819-1384 service monthly.
I'd like to find and copy (or potentially cut) the phone number.
The number and placement within the text will vary, as will all the text vary, but the phone number will always be formatted that way. [sp]xxx[sp]xxx-xxxx[sp]
Any help would be appreciated.

If you can get the text into a KM variable, you can extract the number quite easily with regex. I've included two possible patterns for doing so in this sample macro based on the info you've shared (with one disabled, since only one at a time is needed) but no doubt there are others that would work too:

Extract Phone Number.kmmacros (3.1 KB)
image

Regex

\d[\d\h-]{11}

(?<=\h)\d{3}\h\d{3}-\d{4}

Perfect - works like a charm, thank you @gglick .
I apologize for not thinking of this before asking the original question.
IF there were two numbers in the string.
Would it be possible to 'pick them both up' into separate variables?
And if only one number, get the one. ??
Cheers-

No problem, @troy. It's certainly possible to collect every phone number in a variable into its own variable, though I find it easier to do so with the For Each loop rather than the Search using Regular Expression action:

Extract Multiple Phone Numbers.kmmacros (4.3 KB)
image

Results

11%20AM
11%20AM

This way, the macro will find as many numbers as exist in the source text, whether it's one or many, and save each to its own numbered variable.

1 Like

thank you @gglick I just didn't think about the 'for every'. ufff - lol. You are very generous with your time and expertise on the forum as are a few others.
I am very grateful. - thank you.

1 Like

Hi @gglick, I have posted this in another thread as well.
I'd like to get the base 10 digit number in a variable and the ext. in another variable
The text I'm searching will usually be like this:

Daytime
(929) 295-4774 ext. 1069

Cell
(929) 295-4774 ext. 1070

But, it could sometimes not have one of the numbers/exts, so it could possibly be only one number listed, either the Daytime or Cell. But it usually will have both numbers listed.
result would be
Var_Phone_Daytime xxx xxx-xxxx
Var_Phone_Daytime_Ext xxxx
Var_Phone_Cell xxx xxx-xxxx
Var_Phone_Cell_Ext xxxx

Any help would be appreciated.
I googled, and tested myself to no avail.

Cheers

Hi @troy,

Using the sample text posted in the other thread and the specifications you listed here, this seems like it should get you started. Let me know if you have any questions.

Save Phone Numbers and Optional Extensions to Variables.kmmacros (8.3 KB)

Results

50%20PM
51%20PM

1 Like