Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

RegEx question: match all strings containing range of characters

Hollingsworth
12 - Quasar
12 - Quasar

I've used trial and error on this and even RTFM, but I can't figure out how to solve this RegEx problem. It seems extremely simple but I've reached the hubris threshold and actually need a solution.

 

Problem:

I need to match all of the strings that contain a range of characters. In the example below, I need to find all of the strings that only contain letters a through d.

 

Constraint:

I want to put this in a macro that would accept the last character and the Action would change only the last letter in the range. Therefore, RegEx that specifies each character won't work for my need.

 

Current Attempt:

I've tried various combinations of the following:

REGEX_Match([Testval], "[a-d]")

REGEX_Match([Testval], "^[a-d]")

REGEX_Match([Testval], "/[a-d]/")

 

and all of them return zero records.

 

Extra Credit:

Ideally, I'd also love to have a RegEx that would allow me to match all of the records where each character in that range only appeared once. (e.g. match abcd, but not aabd)

 

I've attached a test workflow and would love your help in soving this problem.

 

Thanks!

John Hollingsworth
Clear Channel Outdoor
5 REPLIES 5
patrick_digan
17 - Castor
17 - Castor

For your original problem, add a * to the end of your first attempt: REGEX_Match([Testval], "[a-d]*"). For extra credit, I will give it some more thought.

MarqueeCrew
20 - Arcturus
20 - Arcturus
regex_countmatches([testval],"a",1)< 2 &&
regex_countmatches([testval],"b",1)< 2 &&
regex_countmatches([testval],"c",1) < 2 &&
regex_countmatches([testval],"d",1) <2


Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
patrick_digan
17 - Castor
17 - Castor

@MarqueeCrew beat me to it! Here is the one line similar to your current Regex that will make sure there are no repeating characters: 

REGEX_Match([Field1], "(?:([a-d])(?!.*\1))*")

Here is the regex tester to explain it.

MarqueeCrew
20 - Arcturus
20 - Arcturus
I like yours more!!!
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Hollingsworth
12 - Quasar
12 - Quasar

Outstanding Patrick! Thank you!

John Hollingsworth
Clear Channel Outdoor
Labels