Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Format Data based on Regular Expression

scollier1993
7 - Meteor

Is there a way to 'apply' a regular expression formatting to an unformatted value of data?

So for example, if my current data contains a field for Social Security Number like this "123456789", could I somehow feed in the Regular Expression requirement like "[\d]{3}-[\d]{2}-[\d]{4}" to reshape all SSN values to "123-45-6789"?

 

Thank you!

3 REPLIES 3
MarqueeCrew
20 - Arcturus
20 - Arcturus

@scollier1993 ,

 

Yes, but NO!!!

 

Regex_Replace([SSN], "(\d3)(\d2)(\d4)", '$1-$2-$3')

 

Left([SSN],3) + "-" + Substring([SSN],3,2) + "-" + Right([SSN],4)

 

The String functions (2nd) expression is much more efficient.

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
atcodedog05
22 - Nova
22 - Nova

Hi @scollier1993 

 

Edit: same as the above solution by @MarqueeCrew. And he has a good point string function are faster than regex 🙂. Just make sure data type of SSN is string before using the above functions.

 

You can use regex_replace like below

REGEX_Replace(ToString([SSN]), "(\d{3})(\d{2})(\d{4})", "$1-$2-$3")

 

Workflow:

atcodedog05_0-1634651823332.png

 

Hope this helps : )

 

binay2448
11 - Bolide

Here is my solution..

Labels
Top Solution Authors