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 add delimiter for parsing data

jaiiracha
7 - Meteor

Hello! I'm currently using the following regex (\s{2}\b) to add a delimiter between my string so I can parse data into columns. I basically need to convert a text file into an excel file that can be used to perform analysis. 

 

An example row of data is as follows:

 

5540134 9/22/22 .9649 432645 53.27 51.16 .11 10/28/22 221025401

 

Using this regex: \s{2}\b

 

Result:

 

5540194 |9/22/22 .9649 |432645 |53.27 |51.16 .11 |10/28/22 |221028001

 

This works fine for the most part except it does not add a delimiter (|) before the .9649 and .11 in the above example. There are many more rows like this, where a delimiter before a decimal point (.) is not added. These decimals are all missing the 0 prior to the decimal point (.) so how can I modify my regex here? Thank you!!!

 

4 REPLIES 4
Qiu
21 - Polaris
21 - Polaris

@jaiiracha 
I was not able to do the same with (\s{2}\b). 
and I am using below and hope that will work for you.

0207-jaisingh1.PNG0207-jaisingh1-A.PNG

jaiiracha
7 - Meteor

@Qiu Thank you for your reply. While this works for the given example, the rest of the rows are not in the same pattern so this would not work.

 

For e.g. the next row of data could be:

 

50927334           9/12/22    .96349    122645   334.27   51.16   .11  9/22/22    22101240133

 

so basically, what I am trying to do is add a delimiter based on the number of spaces (2 spaces) between each segment of the string. With the regex = \s{2}\b 

I am able to add a delimiter between the string for all segments of the data except for the segments that begin with a decimal point (.9649, .11). Is there any way I could fix this?

 

This is the output that I currently get: 

50927334|           9/12/22    .96349|    122645|   334.27|   51.16   .11|  9/22/22|   22101240133

 

This is the output that is needed:

 

50927334|           9/12/22|    .96349|   122645|   334.27|   51.16|   .11|  9/22/22|    22101240133

 

Notice in the desired output, there is a delimiter before .96349 and .11

 

Could you/anyone help with this?

 

Thank you!

Raj
16 - Nebula

This will work for you

 

Raj_0-1675746459808.png

 

binuacs
21 - Polaris

@jaiiracha one way of doing this

binuacs_0-1675756797095.png

 

Labels