Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

RegEx Expression - Remove Trailing Zeros

ScottC1971
7 - Meteor

Hello all,

 

RegEx Expressions honestly escape me.  I have tried to learn to use them but for some reason the logic to use them doesn't hit home...yet.

 

I am trying to create a RegEx Expression that will remove trailing zeros.

 

I have example values like:

AJVC000

AJVC600

AJVC610

AJVC650

 

What I want are:

AJVC

AJVC6

AJVC61

AJVC65

 

There are some exceptions like:

AJVC601

 

In this case I do not want to remove any characters.

 

Any ideas or suggestions on how to learn to write these expresssions and what do I need to solve my current situation?

 

Thank you,

 

Scott

6 REPLIES 6
Luke_C
17 - Castor
17 - Castor

Hi @ScottC1971 

 

No need for regex, just a trimRight()

Luke_C_0-1666983824466.png

 

 

ScottC1971
7 - Meteor

Luke,

 

I agree that I could do that but if I wanted to use a RegEx expression how would you do that?

MarqueeCrew
20 - Arcturus
20 - Arcturus

@ScottC1971 

 

TrimRight

TrimRight(String, y): Removes character in the string (y) from the end of the string (String). Y is optional and defaults to trimming white space.

Example

TrimRight("John Smith   ") returns "John Smith".

TrimRight("John Smith**","*")returns "John Smith".

 

Cheers,

 

 mark

Alteryx ACE & Top Community Contributor

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

I agree that I could do that but if I wanted to use a RegEx expression how would you do that?

Luke_C
17 - Castor
17 - Castor

Hi @ScottC1971 

 

Here's one expression that works, but would still strongly recommend the string function. Regex is not as efficient from a computational standpoint.

 

Regex_Replace([Field1],'([A-Z][1-9]+?|[A-Z])0+\>','$1')

 

Luke_C_0-1666987222200.png

 

 

binuacs
21 - Polaris

@ScottC1971 One way of doing this

 

binuacs_0-1666996630857.png

 

Labels
Top Solution Authors