How to "extractregex" multiple lines of metadata?

How to extract regex from multiple lines ("Metadata") in SalesForce from the start of a word and capture everything in between until a specified character or word?

E.g.:

Name:
Email:
Case Reason:
Message:
URL:
Type:

Etc.....

1 Like

Hi, and welcome to the forum! :slight_smile:

The documentation for the site command has info on how to extract specific things using a regular experession:

It's also useful to experiment with your regex in an interactive playground like this one: https://regexr.com/

Let me know if that helps!

Hi Scott,

Thank you for your reply. Yes, I have used {=extractregex({site: text}, "Name: ([\w ]+)")} to extract single lines of information, however, I have yet to figure out how to extract multiple lines at once, that also include words and URL's (all characters). I am using {=extractregex({site: text}, "User Details([\w\W\s ]+)")}, which extracts from "User Details" but keeps going way past "Okay to Notify" (captures most of the whole page due to \W and \s ). What can I do to have it capture everything between "User Details" and have it stop at "Okay to Notify" without extracting everything after? I have historically needed to manually copy and paste all the meta data details (example below) and send in some emails/messages.

User Details
Name: John Smith
Email: john.smith@12345.com
Case Reason: Broken Link
Message: Hello
Profile URL:
Browser: Chrome
OS: Windows - 10

Item Details
Type: ABC
Id: 123456
Title: XYZ
External URL: https://blaze.today/

Context Details
Feedback Location: ABC
Type: ABC
Id: 123456
Title: ABC
Location: https://blaze.today/

Okay to notify: Yes

Something like this would work:

Set up the example text:

{text=" User Details
Name: John Smith
Email: john.smith@12345.com
Case Reason: Broken Link
Message: Hello
Profile URL:
Browser: Chrome
OS: Windows - 10

Item Details
Type: ABC
Id: 123456
Title: XYZ
External URL: https://blaze.today/

Context Details
Feedback Location: ABC
Type: ABC
Id: 123456
Title: ABC
Location: https://blaze.today/

Okay to notify: Yes"}

Specific section:

{=extractregex(text, "User Details\n([\s\S]+)\nOkay to notify")}

Thank you for that additional insight and information! That worked perfectly.

Another quick question. Is there a way to specifically capture the second instance of a word? E.g. "Type" appears twice on that list. Can I capture only the second instance of "Type"?

Sure, if you can put a wild card match before what you are looking for, it will expand to the available space. For example to get the second "Type" line:

Set up the example text:

{text=" User Details
Name: John Smith
Email: john.smith@12345.com
Case Reason: Broken Link
Message: Hello
Profile URL:
Browser: Chrome
OS: Windows - 10

Item Details
Type: ABC 1
Id: 123456
Title: XYZ
External URL: https://blaze.today/

Context Details
Feedback Location: ABC
Type: ABC 2
Id: 123456
Title: ABC
Location: https://blaze.today/

Okay to notify: Yes"}

Specific section:

{=extractregex(text, "[\s\S]*(Type: .+)\n")}

Thank you! This was a big help in solving my problem.

And what if I want to capture everything after the 2nd "Type:" (excluding Type itself)?

1 Like

You would move the "Type:" outside of the parenthesis. Everything in the parenthesis is what is returned by the function.

Thanks again. You've been super helpful.

Text Blaze has been awesome and really useful. I still am learning how to utilize it for my needs but so far it's been a game-changer.