Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Extract the first two words from a string?

Topic Labels: Formulas
Solved
Jump to Solution
99 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Ruth_Nelson
5 - Automation Enthusiast
5 - Automation Enthusiast

I have string fields and I want to extract the first two words (minus any punctuation or special symbols). Ideally, they would remove the white space and capitalize each word as well.

So a field with “Midnight: A Tale” = “MidnightA”. 

”What’s New in Books” = “WhatsNew”

 

I’ve looked all over to find a way to get two words, but can only find out how to get one. I got into RegEx a bit, but couldn’t figure out how to account for the punctuation/symbols. If someone has a slick way to extract the first two words of a string, I’d be eternally grateful!

1 Solution

Accepted Solutions

Hello,

Someone may have an easier solution, but you could try the following.

Here is the result that I get (column "first 2 words"):

 

Pascal_Gallais_6-1728988603880.png

 

Formula "Word1" extracts the first word:

Pascal_Gallais_2-1728988174691.png

 

Formula "Remainder" extrats the rest of the sentence if it exists:

Pascal_Gallais_3-1728988271720.png

Formula "word2" extracts the second word from the remainder:

Pascal_Gallais_4-1728988318107.png

Formula "First 2 words" concatenates Word1 and Word2 and removes characters " ' "and " : " :

Pascal_Gallais_5-1728988446244.png

You will need to complete the REGEX_REPLACE function with all special characters that you wish to remove (as i did with the dot for example)

Regards,

Pascal

 

See Solution in Thread

4 Replies 4

Hello,

Someone may have an easier solution, but you could try the following.

Here is the result that I get (column "first 2 words"):

 

Pascal_Gallais_6-1728988603880.png

 

Formula "Word1" extracts the first word:

Pascal_Gallais_2-1728988174691.png

 

Formula "Remainder" extrats the rest of the sentence if it exists:

Pascal_Gallais_3-1728988271720.png

Formula "word2" extracts the second word from the remainder:

Pascal_Gallais_4-1728988318107.png

Formula "First 2 words" concatenates Word1 and Word2 and removes characters " ' "and " : " :

Pascal_Gallais_5-1728988446244.png

You will need to complete the REGEX_REPLACE function with all special characters that you wish to remove (as i did with the dot for example)

Regards,

Pascal

 

JuniorL
4 - Data Explorer
4 - Data Explorer

Here’s a formula that accomplishes your requirements. Make sure to replace {YourField} with the actual name of your field containing the strings. 

 

 

UPPER(
    LEFT(
        REGEX_REPLACE(
            REGEX_EXTRACT({YourField}, '^(\\w+)[^\\w]*(\\w+)'),
            '[^A-Za-z0-9]', ''
        ),
        1
    )
) & 
UPPER(
    MID(
        REGEX_REPLACE(
            REGEX_EXTRACT({YourField}, '^(\\w+)[^\\w]*(\\w+)'),
            '[^A-Za-z0-9]', ''
        ),
        2,
        1
    )
)

 


Hope this helps. 

Junior L.
Founder and Consultant at Waybase Studio

Thanks for the help! This formula returns the first two letters of the field, rather than the first two words.

Thank you, Pascal, this worked perfectly! For others trying it, I did include an additional field to capitalize the second word before concatenating them.

IF({File second word}, UPPER(LEFT({File second word}, 1)) & (REGEX_EXTRACT({File second word}, "(?:.)([^ ]*)")))