Regex -- Harvest Variables From Multi Line Text

I realize more than a little help is needed to accomplish my goal.
Appreciate any input -
I'd like to 'pull' these variables from the text.
Address_Street (the full line after the text 'Print this lead')

The example text will always be in the middle of a long string of text but will always be preceded by:
Set Status
(I also have attached the complete block of 'master' text if that is of help)
TestDataFor (2.3 KB)

Here is the example text:

Set Status
Avertta, Tammy

(929) 295-4774 ext. 1047

(929) 295-4774 ext. 1048


Rate this lead
Print this lead
213 Maple Ave
New Hampton, NY 10958


DetailsEmailNotes & RemindersHistory
Clean House Interior (Maid Service)

Job #: 131584913
Additional HomeAdvisor Pros Matched: 2
Service Description

Consumer Comments:
In need of kitchen, bathrooms, living room and dining rooms cleaned. Just the upstairs which include 3 bedrooms, 2 baths, living room, dining room, kitchen, steps and landing

What kind of location is this?:

Cleaning Type Needed:
Recurring Service

Request Stage:
Planning & Budgeting

Desired Completion Date:
1 - 2 weeks

I usually find the best way to approach this kind of task is to avoid the temptation of having one super-RegEx that will extract everything and simply do it several bites.

Set Status\n(\w*), (\w*)


(Note: This is not mine, but from the people at RegExRx)

...and so on.

It may not be super-elegant, but it looks to me as if your example text would allow you to extract all the fields you need in this way.

1 Like

thank you @Rather - I did a bit of looking around but could not find an 'easy' answer - go figure.
How to 'match' the complete next line of text ie. I'd like to get the line after 'Print this lead' as that text is always the 'header' to the street address.
The following regex works if there is no space, but the space is there

Print this lead
110 waters edge

the goal would be to end up with 110 Waters Edge as the match.
Thank you again.

The space can be put in quite easily with \s.

Your expression would then be:

I don't know much about US address conventions or postcodes, but perhaps something like this would give you more detail:


\d is a digit
{4,6} means you want between 4 and 6 of those digits

Just a starter, and you'll soon be doing much more sophisticated expressions, I'm sure!

Good luck.

1 Like

I'd like to get the base 10 Digit number in one variable and the extension in another.
To start with:
Does not extract the initial 10 digit number on

(929) 295-4774 ext. 1069

I can't run your suggested
Because sometime the client does not enter a Cell and other times may not enter a daytime number. So I'll have to run them in two different searches.

Nor does the regex
\b(?<![%+$.-])a-z0-9 @a-z0-9 .[a-z]{2,6}\b
seem to find the email address -
I did find this works:
%+-]+@[A-Z0-9.-]+.[A-Z]{2,}\b courtesy of:

I'd like to get the base 10 Digit number in one variable and the extension in another.

OK. I don't know if these are being entered in a freeform field. Assuming so, then we will have to deal with:

  • the length and format of the number; and
  • the way the person abbreviates extension

It seems the telephone number is made up of digits; hyphens; spaces and brackets.

This would catch a number with 10-14 of those characters:
(I'll let you decide how many characters you need.)

For the next part, I have seen people use:

  • ext 1069
  • x1069
  • extension: 1069

and so you would want to catch all of those.

This expression:

should isolate:

  1. any 'word' of between 1 and 9 characters from "extension"
  2. a spacer made up of a tab, a space, a full-stop, a colon or any combination of up to 3 of those things
  3. a sequence of between 3 and 5 digits, which is the only part actually captured.

Nor does the regex
\b(?<![%+ $.-])a-z0-9 @a-z0-9 .[a-z]{2,6}\b
seem to find the email address

Yep, my bad. I let some spaces slip in and it should be:

However, if you've found something that works, all good!

1 Like

Hey @troy,

Here's an example that works with the sample data you posted.


Regex – Harvest Variables From Multi Line Text v1.00.kmmacros (16 KB)


@ccstone this macro is awesome! I really appreciate your time.
The one thing that seems to not be 'clean' is the First Name, it returns more text that just the first name.
I've taken a bit of time to look at the RegEx and googled a bit and have learned a lot by looking at your example.

Hey @troy,

Give me a good example, and I'll fix it.


For the first name,
Using the macro you posted and the 'embedded' data in the initial action. (initialData)
It returns the first name with a number of additional lines of data.
Just need the first name.

Hmm – I thought I'd tested that...

Oh, I relied on the view in the editor instead of looking at the variable in the prefs. Oops...

This should fix it.

Search using Regular Expression.kmactions (686 B)