Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Formula to search for substring inside string where not part of another word

froseph
6 - Meteoroid

Hi All,

 

I'm trying to use a formula to perform a "match", by searching for a substring inside a string field, where the substring is not part of another word (i.e. preceding, ending or being contained within another word comprised of letters).

 

For example, I want to search for the substring 'but' across a dataset, and produce the output below:

 

Column IDString Search SubstringMatch Flag
1BUTTERBUTNo Match
2TIS BUT A SCRATCHBUTMatch
3HALIBUTBUTNo Match
4REBUTTALBUTNo Match
5BUTBUTMatch
6BUT WHYBUTMatch
7ENDING SENTENCE WITH BUTBUTMatch

 

I'm currently using a Contains function, however this will provide a match for any of the above strings, which is not what I'm looking for. My next step is to experiment with FindString and Contains, but I would imagine there's a more elegant solution (possibly using RegEx?)

 

Would appreciate any support on this requirement, or to be pointed in the direction of any other similar asks (which I could not find on Community)

 

Thanks!

 

5 REPLIES 5
fmvizcaino
17 - Castor
17 - Castor

Hi @froseph ,

 

Attached is a solution using a find/replace + formula tool.

fmvizcaino_0-1589232338019.png

 

Let me know if you need further assistance.

Best,

Fernando Vizcaino

 

 

jdunkerley79
ACE Emeritus
ACE Emeritus

Hi,

 

If you want to use RegEx the trick is the \b to identify a word boundary. Converting this into a formula becomes:

 

REGEX_Match([String ], ".*\b" + [Search Substring] + "\b.*")

 

Have attached a sample to get you started.

 

 

grazitti_sapna
17 - Castor

Hi @froseph ,

 

Please take a look for the attached solution using RegEx tool.

Sapna Gupta
froseph
6 - Meteoroid

Perfect - Thanks Fernando, this works great. In the end I opted for a RegEx solution as the match was embedded in a slightly larger formula. 

froseph
6 - Meteoroid

Many thanks - This is exactly what I was looking for and works a charm! 

Labels