Extracting Data from Inside a Parentheses
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
How do I extract 'Belgium' from 'BE (Belgium)'?
I looked for solutions here but somehow, I am only getting 'BE' as output.
Thank you.
Solved! Go to Solution.
- Labels:
- Best Practices
- Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @crazybeauti_ful,
can you explain the wider context? Do you always want to extract what is inside two brackets? Or do you always want to get the word Belgium? Can you provide a minimal sample?
If you can't provide a sample, here are some things you might want to look for: Regex and Formula.
Best
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @crazybeauti_ful, you could use the regex tool and construct relevant Regex expression to parse out the text between brackets. Attached is a sample to help you get started and expand upon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @grossal , I need to always get the data inside the parenthesis. I did try regex but I only got either the first 2 letters (outside the parenthesis) or 0.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
HI @crazybeauti_ful,
here is a Regex to achieve it. It's a bit tricky because you have to escape the parenthesis and use them in order to catch it.
Output:
Regex:
Regex-Code for easy copy paste:
.*\((.*)\).*
Workflow attached. Let me know if it works for you!
Best
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
I took a different approach, I used text to columns and used the ( as my delimiter. Then I used a formula to remove the other ) and that would just leave me with the text inside the parentheses. See the attached file and let me know if it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I like your thinking @dannyg !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Can someone explain the syntax for the solution, please?
.*\((.*)\).*
With all the parentheses I'm having trouble understanding the different pieces of it. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Would love to have this formula saved somewhere but RegEx doesn't have that option. how would you wite this out for the Multi-Field Formula tool (where I can save the expression)?
PS - why don't the other formula-based tools have the ability to save expressions? I use the Multi-Field tool in cases where I could just as easily use a Formula tool only because I've got the expression I need save there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@Rob48 this would be the formula for a column called "Field" :REGEX_Replace([Field], ".*\((.*)\).*", "$1")
it replaces the whole expression with the first capture group (a capture group is what is in () and $1 calls back to the first capture group), which would be Belgium in this case
