Alteryx Designer Desktop Discussions

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

Regex question

Emil_Kos
17 - Castor
17 - Castor

Hi,


I am still learning regex and I would kindly ask the community for help.

 

Can someone provide me with information on how wright regex that will remove | (vertical dash) as the last sign?

 

Usually I have more then one so it should remove one or more of them but only if vertically dash is the last character.

 

 

Input

ABC|||||

Expected output:
ABC

 

I also have 

ABC|ABD||||

 

Expected output:

ABC|ABD

 

I hope that makes sense 🙂 

15 REPLIES 15
afv2688
16 - Nebula
16 - Nebula

Hello @Emil_Kos ,

 

I'm no expert either bt you could try using this:

 

REGEX_Replace([Field1], '(.*\>)(\|+)', '$1')

 

This removes the pipelines at the end of the word.

 

Regards

Emil_Kos
17 - Castor
17 - Castor

Hi @afv2688,

 

Thank you for taking a look. 


Something isn't working as expected. 

 

It removed also | from the middle of the string and If that was the case he didn't remove them from the end of the string. 

 

 

afv2688
16 - Nebula
16 - Nebula

Hello @Emil_Kos ,

 

You are telling me it's working the other way around? That's weird!

 

I mean I'm getting the results as expected, could you share some more examples to see what is going on with my tests?

 

Untitled.png

 

Regards

Emil_Kos
17 - Castor
17 - Castor

Hi @afv2688,

 

I believe it is related to the dot at the end:

 

Emil_Kos_0-1616147993265.png

 

afv2688
16 - Nebula
16 - Nebula

Hello @Emil_Kos ,

 

modified it a little bit:

 

REGEX_Replace([Field1], '(.*\>\.*)(\|+)', '$1')

 

Regards

afv2688
16 - Nebula
16 - Nebula

Also, a less complicated solution:

 

REGEX_Replace([Field1], '\|\|+', '')

 

Regards

Emil_Kos
17 - Castor
17 - Castor

Hi @afv2688,


I actually currently use this formula 😀


The only problem with it is that if the last character is a dash and it is only one it will not remove it. 

 

Currently I have another formula tool that is correcting this but I wanted to explore the topic and learn how to do it with one regex tool 😀

Emil_Kos
17 - Castor
17 - Castor

Hi @afv2688,


I think this mock data will better represent my data set

 

AB ds,adsaC|ABds a,dC.|||||||
ABC, ABC|ABC ABC ABC”|||||||
ABC, ABC|ABC ABC ABC”|


The output from the more complicated solution that you have provided:

Emil_Kos_0-1616149391708.png

 

afv2688
16 - Nebula
16 - Nebula

Hello @Emil_Kos 

 

Ok then, not elegant at all:

 

REGEX_Replace(REGEX_Replace([Field1], '(.*\>)([\W*&^\|])(\|*)', '$1$2'),'(.*\>)(\|*)','$1')

 

but it became a personal challenge to get it XD

 

Regards

Labels