Skip to main content
Solved

Process a long text field to return an array based on conditions

  • July 12, 2023
  • 3 replies
  • 29 views

Forum|alt.badge.img+2

I have a long text field that takes the food and the preference of the user.

Sample Input:

Burgers (Enjoy), Pasta (Ok), Seafood (Nope), Pork (Ok), Beef (Ok), Vegies (Enjoy)

 

I want to get all the texts that are "Enjoy"-ed by the user.

Expected Output:

Burgers, Vegies

 

What formula can I use to get this output?

Best answer by Sho

I tried to make an formula in Regex.
How does this work?

REGEX_REPLACE({Foods},"\\w*\\s\\((Nope|Ok)\\),?\\s?|\\s\\(Enjoy\\)\\s?","")

 

3 replies

Forum|alt.badge.img+21
  • Inspiring
  • 560 replies
  • Answer
  • July 13, 2023

I tried to make an formula in Regex.
How does this work?

REGEX_REPLACE({Foods},"\\w*\\s\\((Nope|Ok)\\),?\\s?|\\s\\(Enjoy\\)\\s?","")

 


Forum|alt.badge.img+2
  • Author
  • New Participant
  • 1 reply
  • July 17, 2023

I tried to make an formula in Regex.
How does this work?

REGEX_REPLACE({Foods},"\\w*\\s\\((Nope|Ok)\\),?\\s?|\\s\\(Enjoy\\)\\s?","")

 


This works fine for the sample data given but isn't working for 3-words. Thanks though!


Forum|alt.badge.img+21
  • Inspiring
  • 560 replies
  • July 17, 2023

I had not verified that case!
Update for multiple words

REGEX_REPLACE({Foods},"[\\w\\s]*\\s\\((Ok|Nope)\\),?\\s?|\\s\\(Enjoy\\)","")