cancel
Showing results for 
Search instead for 
Did you mean: 

REGEX, Match Acronym

SOLVED
hellyars
Pulsar

REGEX, Match Acronym

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
Pulsar

REGEX, Match Acronym

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??

hellyars
Pulsar

Re: REGEX, Match Acronym

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.

Re: REGEX, Match Acronym

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

Re: REGEX, Match Acronym

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,

Re: REGEX, Match Acronym

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

Re: REGEX, Match Acronym

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,

Re: REGEX, Match Acronym

@Thableaus 

Thanks for sharing this tip.  This is great!

Re: REGEX, Match Acronym

@amitkellawan 

 

Check out this string of posts.