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

Parsing a specific number of Characters form a string

MarqueeCrew
20 - Arcturus
20 - Arcturus

I received a private message from @Desa19 asking for help:

 

Hello MarqueeCrew,

 

I thought I should send this directly to, I realised you have been offering some very good assistance to issues relating to Parsing, unfortunately I could not exactly solve my case using all the hints I read from your contributions. Well here is my Problem:

 

I am having some difficulties using Regex to extract a specific part of a string field within my Data.

I have for example a field with the following string: 99999998_20180501_001_21_11+22_ORDERS

 

I will like to extract the Year and Month (marked in green) for each single record within that field. The field ist automatically generated and the date changes depending on the date of input of the record (YYYYMMDD), else the format remains the same for all the records. Only exception could be the prefix that could vary between "ORDERS" and "OFFERS"

 

I will appreciate your assistance.

 

Thanks

Desa

 

I'm going to answer via the forum and welcome competing solutions.

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
2 REPLIES 2
MarqueeCrew
20 - Arcturus
20 - Arcturus

@Desa19,

 

If the string is FIXED and the date component always is in the same position, skip Regex with:

DateTimeParse(Substring([Field1],9,8),"%Y%m%d")

 

If the beginning of the string is variable in length, Regex is a quick help:

DateTimeParse(REGEX_Replace([Field1], "\d+_(\d{8})_.*", '$1'),"%Y%m%d")

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Desa19
7 - Meteor

Thanks MarqueeCrew,

 

the second option you just proposed is most adapted to my case since there is the possibility that the beginning of the string might vary, this will work just well, I am grateful for that.

 

Best regards,

Desa

Labels