Alteryx Designer Desktop Discussions

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

regex_match with ()

becki
8 - Asteroid

in a formula tool, I have this:

 

if REGEX_Match([nameplate],'C-MAX|Focus|FocusRS|MKZ|Taurus') then 0 else [Wheelbase] endif

 

but if in the [nameplate] field, there is Focus (NA) and it's getting ignored in this formula tool.  I've tried the following and none of it works:

 

Focus (NA)

"Focus (NA)"

`Focus (NA)`

'Focus (NA)'

Focus*

 

How do i convince regex_match to match on something with a space and ()?  thanks

 

 

 

 

 

6 REPLIES 6
tcroberts
12 - Quasar

Hi becki,

 

Theres a couple of ways to approach this. If you waont to capture all things that have "Focus" followed by any number of characters, you could use:

 

if REGEX_Match([nameplate],'C-MAX|Focus\s.*|FocusRS|MKZ|Taurus') then 0 else [Wheelbase] endif

 

The "\s" indicates that there should be one whitespace in that location. The "." character says: "any type of character", and the "*" says, 0 or more of the previous character.

 

Let me know if this isn't working.

 

Cheers!

 

kat
12 - Quasar

Hi @becki

 

The issue with the brackets are that these are metacharachters. This means that they have a special meaning in Regex. To get around this you need to escape them - this turns them back into their literal character - i.e. a bracket instead of a start to a group. The way to escape something is to put a \ in front of it.

 

Here is an example for yours. The \s represents a space.

 

regex.PNG

 

Hope that helps!

Katrin

becki
8 - Asteroid

perfect, thanks!

becki
8 - Asteroid

thanks.  that worked too!

vvissamsetty
8 - Asteroid

Hi Guys,

This was very helpful, thanks for sharing. However, I'm kind of stuck on the next step. I'm trying to select multiple strings in a column which have (). 

 

American Depository Receipt (ADR)

Corporate Bond

Government Bond

Global Depository Receipt (GDR)

 

REGEX_Match([Security Type], 'American Depository Receipt\s\(ADR\)\Corporate Bond/Government Bond\Global Depository Receipt\s\(GDR\)') I'm trying to use this formula to filter these strings but it isn't working. Is there any other way I can do this?

chinu267
8 - Asteroid

If I have not understood you wrong, use below in a formula tool against the field and verify.

Create a Boolean field and test the inputs.

True is 1 False is 0

 

IF REGEX_Match([Security Type], "American Depository Receipt\s\(ADR\)") THEN 1
ELSEIF REGEX_Match([Security Type], "Corporate Bond") THEN 1
ELSEIF REGEX_Match([Security Type], "Government Bond") THEN 1
ELSEIF REGEX_Match([Security Type], "Global Depository Receipt\s\(GDR\)") THEN 1
ELSE 0
ENDIF

Labels