Alteryx Designer Desktop Discussions

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

Can i use regex for this?

krishnagandhi
8 - Asteroid

I have data that sometimes has a commas after 10 characters and some that don't. what i want to do is consistently have a comma after each 10 digits, unless there are only 10 digits. So basically i want the following:

45028357424502938101,4502938115
4502835734
4502755826450290882145029381104502938415
4502755826,4502908821

To look more like this:

4502835742,4502938101,4502938115
4502835734
4502755826,4502908821,4502938110,4502938415
4502755826,4502908821

 

I'm hoping there is a regex expression to help with this.

 

Thanks!

6 REPLIES 6
atcodedog05
22 - Nova
22 - Nova

Hi @krishnagandhi 

 

Honestly i dont know whether this can be solved only with regex

 

Here is a workflow for the task.

Output:

atcodedog05_0-1603992979557.png

 

Workflow:

atcodedog05_1-1603992991798.png

 

Hope this helps 🙂 I look for a regex way


If this post helps you please mark it as solution. And give a like if you dont mind 😀👍

atcodedog05
22 - Nova
22 - Nova

Hi @krishnagandhi 

 

Here is way using Regex and single formula

 

TrimRight(Replace(REGEX_Replace([Text], "(\d{10})","$1,"), ",,", ","),",")

Output:

atcodedog05_0-1603993276208.png

 

Workflow:

atcodedog05_0-1603993207087.png

Select tool is used to increase datatype size to avoid truncation.

Hope this helps 🙂


If this post helps you please mark it as solution. And give a like if you dont mind 😀👍

jdunkerley79
ACE Emeritus
ACE Emeritus

My default answer to Can I use regex for this? is yes.

 

So here you go:

 

(\d{10}(?=.))

 

will match blocks of 10 as long as a character after it

 

Works fine in a REGEX in substitute mode with $1, as the replacement text

 

Sample attached. 

atcodedog05
22 - Nova
22 - Nova

Hi @jdunkerley79 

 

There are duplicate commas in your output can something be done about it.

atcodedog05_1-1603995555419.png

 

jdunkerley79
ACE Emeritus
ACE Emeritus

Good spot - too small for my old eyes.

 

Use:

(\d{10}(?=\d))

 

Works fine now 

atcodedog05
22 - Nova
22 - Nova

Perfect 👌

 

Thats amazing @jdunkerley79 😎

Labels