Alteryx Designer Desktop Discussions

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

How to remove specific characters at the start and end of a string

KCT
5 - Atom

 

 

I cant find a formula to remove the specific characters at start and end of a string.

 

Can you assist? Thx

 

Trade ID                                                                        New Trade ID

82_AE2020102280737096_80737094_20201026_NE         AE2020102280737096_80737094_20201026

82_11289116747_20232331_NE                                      11289116747_20232331

85_DBH-QUR76N_NE                                                    DBH-QUR76N

85_DBH-MAB3ME_NE                                                   DBH-MAB3ME

7 REPLIES 7
BrandonB
Alteryx
Alteryx

Here you go! Workflow attached

 

regex.png

MarqueeCrew
20 - Arcturus
20 - Arcturus

@KCT,

 

No RegEx:

 

TrimRight(IIF(left([Trade ID],3) IN ("82_", "83_"),substring([Trade ID],3)),"_NE")

 

Note:  I didn't test the formula.

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
vizAlter
12 - Quasar

Hi @KCT — Simple "Left" and "Right" functions can give you the solution too:

 

vizAlter_0-1603828126911.png

 

vizAlter
12 - Quasar

@KCT — Also, try this through a RegEx tool with Parse output method, like below:

 

^\w{2}_(.*)_\w{2}$

 

vizAlter_0-1603828647780.png

 

KCT
5 - Atom

Thanks Brandon.

 

How do I interpret the expression that you suggested .*?_(.*?)_NE

 

If I have another record of trade id on the input

 

example 3940OC9105050191012_P:EUR_R:HKD_1_1 and the result will remain 3940OC9105050191012_P:EUR_R:HKD_1_1, can I put a condition within parse to default to Trade ID?

 

KCT
5 - Atom

Thanks Mark. There is an error on the formula on Malformed If statement.

BrandonB
Alteryx
Alteryx

Instead you might want to use the following 

 

.*?_(.*)_

 

The parenthesis indicates a marked group so what this updated formula is saying is to only pull the data between the first and last underscore. My previous formula would only pull data until the last underscore and an NE. Can you try this regular expression and let me know if it works better for you?

Labels