We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

contains multiple strings?

becki
8 - Asteroid

i read this - https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Filter-on-Multiple-Contains/m-p/309402

 

but what i need is something like :

 

contains([field1], "mustang" or "fiesta" or "f150") to change a set of values, based on the value of a field, in this case, the nameplate field or do i have to do:

Contains([field1],"mustang") OR

Contains([field1]),"fiesta")

 

thanks

 

8 REPLIES 8
tcroberts
12 - Quasar

You could instead use something like:

 

REGEX_Match([Field1], 'mustang|fiesta|f150')

Let me know if you have more questions about building the regex, or if this doesn't work for you.

 

Cheers!

becki
8 - Asteroid

thanks.  can you use that with a formula tool so I can change the value of the field [wheelbase] based on values in the field [nameplate]?  thanks

 

becki
8 - Asteroid

REGEX_Match([nameplate],"Mustang"|"Figo") doesn't work, even If I use 'Mustang' or double quotes.  the error , in the formula tool is "unknown operator "|", did you mean "||"? and if I put that in, then I can't change the field "wheelbase" in formula since it's a numeric. 

tcroberts
12 - Quasar

Yes, you'd want to enter an expression something like:

 

IF REGEX_Match([Field1], 'mustang|fiesta|f150')
THEN Value1
ELSE Value2
ENDIF

This should do what you want. If you can provide a sample of data I could try to put an actual example together.

 

Let me know if you need further help setting this up.

tcroberts
12 - Quasar

You want the | character inside the quotes. 

 

The second argument should be a single string, with things you want to look for separated by |.

 

The | (pipe operator) is used to mean the logical OR operation.

becki
8 - Asteroid

thanks!  and duh, I need to read for context not for speed! 

JFurda
8 - Asteroid

This does not appear to be working for me in a formula tool. It works with a single argument, but when I put in multiple arguments, it does not work (does not change the value upon a match/true result)
Output Column: FIELD2


IF(Contains([FIELD1], '2366|2302'))
THEN "N"
ELSE [FIELD2]
ENDIF

 

I'm using Contains() because the value in the FIELD1 could have a leading zero or even additional text.

 

What am I missing? 

ColinG
8 - Asteroid

I found this trying to remember how to get Contains to use multiple matches, and it lead me astray. I forgot that Regex_Match requires a full 100% match (no partials) on the pattern. I think a better analog for "contains" with multiple options would be this, which worked for my use case, and 0 would obv mean no match.

 

REGEX_CountMatches([Field1], 'mustang|fiesta|f150') 


If you are wanting to replace the values as the parent question asked, then another option would be to use the Find and Replace tool.

Labels
Top Solution Authors