Alteryx Designer Desktop Discussions

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

Regex Parse between two strings

elamp6
7 - Meteor

I'm trying to use the Regex - Parse tool to pull JAN-19 to FEB-19 from the following string:

Currency:  USD                                       Period:  JAN-19 to FEB-19                              Page:      1

 

I'm currently using this formula

Period:\s{2}(.+)\s{3,}

which is yielding this:

JAN-19 to FEB-19                              Page:   

 

I'm getting tripped up on what to add to get rid of the spaces and "Page:" Any ideas?

4 REPLIES 4
Jonathan-Sherman
15 - Aurora
15 - Aurora

Hi @elamp6,

 

You could use the following expression in Regex parse mode:

 

Period:\s+([A-Z]{3}-\d{2}\s+to\s+[A-Z]{3}-\d{2})

 

Jonathan-Sherman_0-1589557566210.png

 

If this solves your issue please mark the answer as correct, if not let me know! I've attached my workflow for you to download if needed.

 

Regards,

Jonathan

 

Hannah_Lissaman
11 - Bolide

In RegEx, the * and + operators are 'greedy'. This means that they will include the maximum possible characters for which the expression can be true. 

 

If you are a ? afterwards, it converts the operator so that it only takes the minimum characters for which it can be true.

 

Try: 

\s{2}(.+?)\s{3,}

 

estherb47
15 - Aurora
15 - Aurora

Hi @elamp6 

Is your format always 3-character month followed by hyphen followed by 2 digit year?

If so, you can try this:

(\u{3}-\d{2}\s+to\s+\u{3}-\d{2})

 

This should just grab the 3 uppercase letters, hyphen 2 numbers, " to " (unsure of # spaces so used \s+), and another set of uppercase letters, hyphen, 2 numbers.

 

Let me know if that helps

 

Cheers!

Esther

elamp6
7 - Meteor

@Hannah_Lissaman 

That makes so much sense. Thank you! I used 

 

Period:\s{2}(.+?)\s{3,}

 

 and got exactly what I need. 

Labels