Alteryx Designer Desktop Discussions

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

Regex to extract Text and Number into different columns

Pranab_C
8 - Asteroid

Hi Champions, 

 

i need help in extracting text and numbers into different columns from this

 

What I have is this:-

 

" Arizona 0 0 (US-AZ) Colorado 0 0 (US-CO)"

"Qatar (QA) 0 0 United Arab Emirates 147 0 (AE)"

" Missouri 70 0 (US-MO)"

" Utah (US- 0 0 UT) Total 217 0"

 

What I need is, i.e. Arizona in one column and zero in another

 

Arizona-0, Colorado-0

Qatar-0, United Arab Emirates 147

Missouri-70

Utah-0, Total 217

 

13 REPLIES 13
AndrewDMerrill
13 - Pulsar

What does the comma mean? Should the output look like this:

Arizona0Colorado0

Or should each pairing be in a new row?

Arizona0
Colorado0

 

Also, there is very little standardization in your data (Very important for Regex). Is what you have included, representative of every case in your data?

flying008
14 - Magnetar

Hi, @Pranab_C 

 

FYI.

录制_2023_12_22_11_45_41_15.gif

 

Input     
Txt     
 Arizona 0 0 (US-AZ) Colorado 0 0 (US-CO)     
Qatar (QA) 0 0 United Arab Emirates 147 0 (AE)     
 Missouri 70 0 (US-MO)     
 Utah (US- 0 0 UT) Total 217 0     
      
Output     
TxtMatchStateIDSKUNum
 Arizona 0 0 (US-AZ) Colorado 0 0 (US-CO) Arizona 0 0 Colorado 0 0Arizona0Colorado0
Qatar (QA) 0 0 United Arab Emirates 147 0 (AE)Qatar 0 0 United Arab Emirates 147 0Qatar0United Arab Emirates147
 Missouri 70 0 (US-MO) Missouri 70 0Missouri70  
 Utah (US- 0 0 UT) Total 217 0 Utah  0 0  Total 217 0Utah0Total217

 

Spoiler
Formula:
REGEX_Replace(REGEX_Replace(REGEX_Replace([Txt],  '\s\([a-z\-]+?\)(?=[^"$])', ''), '\([a-z\-]+?([\d\s]+?)[a-z]+?\)(?=[^"$])', '$1'), '\s\([a-z\-]+?\)(?="|$)', '')​

Parse:

^["\s]+([[:alpha:]]+)\s+(\d+)\s[\d\s]+(?:([[:alpha:]\s]+)\s+(\d+))?​

 

Pranab_C
8 - Asteroid

Thank you so much for taking a look at this, worked for all except the row that contains

"Qatar 0 0 United Arab Emirates 147 0"

flying008
14 - Magnetar

Hi, @Pranab_C 

 

So, like this string of "Qatar 0 0 United Arab Emirates 147 0", what result are you want get ?

Pranab_C
8 - Asteroid

Input

Qatar 0 0 United Arab Emirates 147 0

Desired Output

Qatar| 0 | United Arab Emirates| 147|

flying008
14 - Magnetar

Hi , @Pranab_C 

 

About the join character for each, you can type a formula after split to adjust it. 

 

录制_2023_12_22_14_00_08_530.gif

Pranab_C
8 - Asteroid

Thank you once again for quickly taking a look at this, can you share the workflow that you have created.

flying008
14 - Magnetar

Hi, @Pranab_C 

 

There is only 2 step for workflow, and i post all expression in above post, you just copy it to your canvas to get it. 

If you can post your want output result data as table, maybe i rebuild the flow as pre.

Pranab_C
8 - Asteroid

Hi Thank you once again, here is the test workflow package, you would notice that its not working for the first row only. It works perfectly for the rest of the information

Labels