Help

How to delete part of a text after and including a hyphen?

Topic Labels: Formulas
3633 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Markus_Wernig
8 - Airtable Astronomer
8 - Airtable Astronomer

If someone could help me with this, I’d be extremely grateful. I can’t figure this out.
This is what I"d like to achieve through a formula:

Screen Shot 2021-08-17 at 5.57.03 PM

Most Track Titles have a name followed by a “space hyphen space” and a suffix.
I’d like to automatically delete everything after and including the “space hyphen space”.
If Track Title is not followed by “space hyphen space”, just copy the Track Title over.

Thank you so much for pointing me in the right direction.

5 Replies 5
Markus_Wernig
8 - Airtable Astronomer
8 - Airtable Astronomer

I have come this far, but it results in an #ERROR! for TRACK TITLE C:

> IF(
>     {TRACK TITLE},
>     SUBSTITUTE({TRACK TITLE},
>     REGEX_EXTRACT({TRACK TITLE}," -.*"),""
>     ))

Welcome back to the Airtable community!

Regular expressions can be tricky to setup. Try this formula. It looks for a string of characters that are not hyphens and then trims any leading/trailing space.

TRIM(REGEX_EXTRACT({TRACK TITLE}, "[^-]*"))

The problem with this formula is that REGEX_EXTRACT returns an error if the pattern does not have any matches.

Thank you so much, kuovonne.

Would you mind adding your line of code to my formula? When I try to do it, I get formula syntax errors.
Thank you!

My formula does not need to be embedded in your formula. It is a standalone formula.

I just tried it. Works beautifully. Thank you so much!!