Using regexp for pulling multiple values out a text string
Hello, I need some help pulling out email addresses from a text string.
My goal is to place these multiple emails listed in the 'Description' column in a separate column, where they'll be separated by ','. Is there way for the search to end before the Sent Date info?
Thank you!
Best Answer
-
Try something like this to make it a bit simpler:
REPLACE(REGEXP_REPLACE(SPLIT_PART(SPLIT_PART(``, 'Sent:', 1), 'To: ', 2), '[^<]+<([^>]+>)', '$1'), '>', ',')
SPLIT_PART(``, 'Sent:', 1)
Gets evertying in your string before 'Sent: ' - drops everything after it
SPLIT_PART(SPLIT_PART(``, 'Sent:', 1), 'To: ', 2)
Gets the entire text in between the To: and Sent: values so you're left with just the email addresses and the aliases
REGEXP_REPLACE(…, '[^<]+<([^>]+>)', '$1')
Finds all occurrences of the email addresses and any values outside of the < > and drops it in favor of what's in the < >. This keeps the trailing > so we can replace it with REPLACE in the last step with commas.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1
Answers
-
Are you wanting the From and To both to be included or just the To? Will the From and To fields only have a single email or would there be multiple emails?
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
@GrantSmith I'm needing just the emails that would be listed in the To field. The emails listed in To field can have multiple email addresses listed. Thank you for your help!
0 -
Try something like this to make it a bit simpler:
REPLACE(REGEXP_REPLACE(SPLIT_PART(SPLIT_PART(``, 'Sent:', 1), 'To: ', 2), '[^<]+<([^>]+>)', '$1'), '>', ',')
SPLIT_PART(``, 'Sent:', 1)
Gets evertying in your string before 'Sent: ' - drops everything after it
SPLIT_PART(SPLIT_PART(``, 'Sent:', 1), 'To: ', 2)
Gets the entire text in between the To: and Sent: values so you're left with just the email addresses and the aliases
REGEXP_REPLACE(…, '[^<]+<([^>]+>)', '$1')
Finds all occurrences of the email addresses and any values outside of the < > and drops it in favor of what's in the < >. This keeps the trailing > so we can replace it with REPLACE in the last step with commas.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
@GrantSmith It worked, thank you!
0
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 659 Datasets
- 116 SQL DataFlows
- 2.2K Magic ETL
- 816 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 82 App Studio
- 45 Variables
- 776 Automate
- 190 Apps
- 481 APIs & Domo Developer
- 82 Workflows
- 23 Code Engine
- 41 AI and Machine Learning
- 20 AI Chat
- 1 AI Playground
- 2 AI Projects and Models
- 18 Jupyter Workspaces
- 411 Distribute
- 120 Domo Everywhere
- 280 Scheduled Reports
- 11 Software Integrations
- 144 Manage
- 140 Governance & Security
- 8 Domo Community Gallery
- 48 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 115 Community Announcements
- 4.8K Archive