# Regex Formula to extract part of a text

**URL:** <https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809>\
**Category:** Get Help\
**Created:** [July 19, 2023, 11:07am UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809 "2023-07-19T11:07:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marloes](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/marloes/32/5926_2.png) [@Marloes](https://community.fibery.io/u/Marloes)\
**Post date:** [July 19, 2023, 11:07am UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/1 "2023-07-19T11:07:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [July 19, 2023, 12:29pm UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/2 "2023-07-19T12:29:40Z")

</div>

> [@Marloes](#):
>
> So the result will be “The Next Level”.

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

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [July 19, 2023, 12:32pm UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/3 "2023-07-19T12:32:17Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![Marloes](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/marloes/32/5926_2.png) [@Marloes](https://community.fibery.io/u/Marloes)\
**Post date:** [July 19, 2023, 12:40pm UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/4 "2023-07-19T12:40:54Z")

</div>

> [@Chr1sG](#):
>
> The result will be 'The Ultimate Workspace", no?

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

> [@Chr1sG](#):
>
> Left(TextField,Find(TextField,“-”)-1)

PERFECT!!

---

<div class="post-metadata">

**Author:** ![Marloes](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/marloes/32/5926_2.png) [@Marloes](https://community.fibery.io/u/Marloes)\
**Post date:** [July 19, 2023, 12:55pm UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/5 "2023-07-19T12:55:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [July 19, 2023, 1:02pm UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/6 "2023-07-19T13:02:35Z")

</div>

Yeah, sorry.  
You probably need something this then:

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

---

<div class="post-metadata">

**Author:** ![Marloes](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/marloes/32/5926_2.png) [@Marloes](https://community.fibery.io/u/Marloes)\
**Post date:** [July 19, 2023, 1:05pm UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/7 "2023-07-19T13:05:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [July 19, 2023, 1:11pm UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/8 "2023-07-19T13:11:20Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [September 20, 2023, 6:07am UTC](https://community.fibery.io/t/regex-formula-to-extract-part-of-a-text/4809/9 "2023-09-20T06:07:52Z")

</div>

A post was split to a new topic: [Extracting name from text](https://community.fibery.io/t/extracting-name-from-text/5181)
