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??
Solved! Go to Solution.
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.
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
Dan
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
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,
Thanks for sharing this tip. This is great!