Regex getting next text entered and next number entered

I'd like to get the FirstName, LastName and phone number (string of 10 digits) into separate variables.
I can't figure out how to ignore the blank line if there is one.
The source data will always be in one of the following formats with the string 'Next Candidate' starting it off.
I tried but just cannot get the regex that would match both scenarios.
Many thanx
(the phone number could also be entered as 8457281111 or 18457281111 so might the best way to capture the number to capture the last 10 digits on that line? - it will always be on a line by itself.

The source data will be formatted in the following way.

Next Candidate

FirstName LastName

845-728-1111
Applied

or this way

Next Candidate
FirstName LastName
845-728-1111
Applied

Give this a try:
Next Candidate[^\w]+(\w+)\h+(\w+)[^\d\(]+([\d\.\- \(\)]+)

This will match:

  1. The exact format you provided
  2. One or more SPACES or TABs between "FirstName" and "LastName"
  3. A wide variety of phone number formats, including:
    • 123-123-1234
    • (123) 123-1234
    • 123.123.1234
    • 123 123 1234

For RegEx details, see: regex101: build, test, and debug regex

Let us know if this works for you.

awesome @JMichaelTX the one issue I see at first is if the phone number is formatted as: 1 914-612-1111
I do know how to then get that number down to the primary 10 digits in another action, but would like to know if it would be possible to cover that possibility in the regex? The code you supplied returns the number including -'s or ()'s.

Basically the last 10 numbers on that line would be nice.
to get 9146121111 regardless of its original format which could be various.
ie. 1914 612-1111, (914) 612 1111, etc etc. I think it's a free field that the applicant can enter anything into that field. I'm not in control of the input but it always shows up to me as numbers with various phone formatting in it.
Thank you as always for your expertise.
I'll be going to regex101 to look at the code you supplied to try to understand it a bit better.
Cheers.

The RegEx I provided above will include any country codes or other digits prior to the 10 digit phone number. If you want the last 10 digits, then this should work:

Example Output

image

MACRO:   Extract 10-digit Phone Number

**Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/9/6/9613b2afdb6aa7713b3c694757e9b9242f4c8a02.kmmacros">Extract 10-digit Phone Number.kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


---


<img src="/uploads/default/original/3X/1/2/12c69d7cbef45f5653f1085398ca119937c934cc.png" width="513" height="1100">
2 Likes