community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

regex_match with ()

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

 

 

 

 

 

Alteryx Partner

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!

 

Highlighted
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

Asteroid

perfect, thanks!

Asteroid

thanks.  that worked too!

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?

Labels