Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

RegEx to parse data of variable lengths

HBarlow
6 - Meteoroid

I have source data which is made up of a company code, company name, date billed, and the amount owed all in one cell in Excel. I need to parse the data into four columns that represent the four elements. I’m having some trouble using the RegEx tool to parse the data, as the company name and the amount owed are variable lengths. The company code will always be 5 digits and the date billed will always be in the same format (mm/dd/yyyy). Any help is greatly appreciated.

 

Source data:

Company information
52073 Binford Tools, Inc. 12/07/2022 ($183.54)
89682 Acme Corporation 10/27/2022 ($1,255.50)
80364 Globex Corporation (Springfield) 11/22/2022 ($546.90)
50074 Gekko & Co of New York Inc 08/30/2023 ($240.75)
83140 Genco Pura Olive Oil Company 01/01/2023 ($605.23)

 

Desired output:

Company CodeCompany NameDate BilledAmount
52073Binford Tools, Inc.12/07/2022($183.54)
89682Acme Corporation10/27/2022($1,255.50)
80364Globex Corporation (Springfield)11/22/2022($546.90)
50074Gekko & Co of New York Inc08/30/2023($240.75)
83140Genco Pura Olive Oil Company01/01/2023($605.23)

 

5 REPLIES 5
danilang
19 - Altair
19 - Altair

hi @HBarlow 

 

Use (\d{5})\s(.*?)\s(\d{2}\/\d{2}\/\d{4})\s(.*) as your regex string.  This will break your input into 4 fields.

w.png

Dan

caltang
17 - Castor
17 - Castor

Alternatively, you can also use:

^(\d+) (.*?) (\d{2}/\d{2}/\d{4}) (\(.*\))$

 

image.png

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Qiu
21 - Polaris
21 - Polaris

@HBarlow 
A completly unnessary complicated one. 
Tried to avoid Regex but failed and landed with a simpler Regex though.

1017-HBarlow.png

flying008
15 - Aurora

Hi, @HBarlow 

 

^(\d+)\s([^\d]+)\s([\/\d]+)\s(.+)$

 

录制_2023_10_17_09_27_05_266.gif

HBarlow
6 - Meteoroid

Thank you, everyone, for your solutions! All of these worked great! I'm new at using RegEx and still learning the nuances.

Labels