Regex Formula to extract part of a text

Hi there,

I want to fix a Regex formula, but bumping into a challenge I can not fix.

We have a text field with a product name. This can be:

  • The Ultimate Workspace
  • The Ultimate Workspace - payment in 3 installments

I want a formula that extracts everything prior to " - …" (including the blank space in front of the hyphen. So the result will be “The Next Level”.

I have tried to make a ReplaceRegex myself. But can’t seem to get the desired outcome.

The result will be 'The Ultimate Workspace", no?

If you are sure that the first hyphen in the string is always the one you want to separate at, then I would suggest the following:

Left(TextField,Find(TextField,"-")-1)

Yes. We use with testing all those products interchangeably so accidentally misnamed. :see_no_evil:

PERFECT!!

Only challenge left. We sometimes have ‘The Ultimate Workspace’ and sometimes we have ‘The Ultimate Workspace - payment in 3 installments’.

If I use this formula, ‘The Ultimate Workspace’ will become ‘The Ultimate Workspac’ due to the -1. Tried to modify, but didn’t find the right solution.

Yeah, sorry.
You probably need something this then:

If(Find(TextField,"-")=0,TextField,Left(TextField,Find(TextField,"-")-1)

No sorry!

Was trying something like this, but because I wasn’t using the find function, my formula came up negative. This is perfect!

Thanks again.

Well, it actually can be done simply with regex replace as well.

ReplaceRegex(TextField, "-.*", "")

1 Like

A post was split to a new topic: Extracting name from text