Alteryx Designer Desktop Discussions

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

REGEX, Match Acronym

hellyars
13 - Pulsar

Here is my sample string.  It is a sample Title or Name of something.  I want to find all Titles that contain EW and only the two digit acronym EW.  I plan to use it in a IF statement.   IF (Contains([Title], 'EW' 0) THEN 1 ELSE 0 ENDIF.  The Contains expression does not work because it picks up anything that contains an "ew" match.  But, I am having trouble coming up with the REGEX expression to capture only the 2-digit EW acronym and only the 2-digit acronym.  Help.

 

 

 

SEW or EW or a New Thing

 

 

 

 

if (Contains([Title], 'TACO',0)) then 1 elseif REGEX_Match([Title], '.*(\bEW)\b.*$') then 1 else 0 endif. ....I think this works??

7 REPLIES 7
hellyars
13 - Pulsar

I should clarify - because I asked a similar question before.

 

Contains([Description],"EW",0)  works but picks up anything with EW in it.  In the sample title above, this expression picks up both SEW and EW.

danilang
19 - Altair
19 - Altair

Hi @hellyars 

 

Here's a regex expression that matches your criteria

 

(^EW .*|.* EW$|.* EW .*|^EW$)

 

It's got 4 parts

^EW .* matches anything that starts with "EW" and is followed by a space

.* EW$ matches anything that ends with "EW" and is preceded by a space

.* EW .* matches anything that is "space EW space"

^EW$ matches anything that is "EW" on its own

 

The pipes specify that you should perform a logical OR 

 

Results

 

regex EW.png

 

 

Dan

 

Thableaus
17 - Castor
17 - Castor

Hi @hellyars 

 

@danilang solution is actually cool, but there is a very useful concept in RegEX that is called "word boundary". It's represented by "\b".

This actually prevents you from going into these tricky traps.

 

So, the match would work this way:

 

REGEX_MATCH([Field1], ".*?\bEW\b.*")

 

Cheers,

danilang
19 - Altair
19 - Altair

Thanks @Thableaus.  Much more elegant. 

 

And now I know something else about Regex.  It's convenient that "\b" works at the beginning and ending of lines as well.

 

 

Dan

Thableaus
17 - Castor
17 - Castor

Yes @danilang "\b" is what is called a positional match, such as "^" and "$".

 

It doesn't actually represent a character, just a position in your pattern. And that position is filled either with non-word characters or no characters at all.

 

Cheers,

papalow
8 - Asteroid

@Thableaus 

Thanks for sharing this tip.  This is great!

papalow
8 - Asteroid

@amitkellawan 

 

Check out this string of posts.

Labels