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.
SOLVED

Specific REGEX remove the letter(s)/number(s) at the end of a string only if the digit is

Billibo418
5 - Atom

Hi,

 

I'm searching for a similar REGEX that remove the letter(s)/number(s) at the end of a string only if the digit is the same than the second group of the string.

 

Exemple :

 

100 10 RUE DES SAPINS RIMOUSKI 10

22 BOUL PRAIRIES QUEBEC

34 4 AV DE LA MOUTARDE 4

22 PO BOX 44

122 B 10E RUE CHIBAUGAMEAU B

 

Result :

 

Remove the 10 at the end of the first line

Remove the 4 at the end if the 3rd line

Remove the B at the end of the 4th line

 

I'm new with Alteryx and it could help me so much.

 

Thank you in advance ✌️

 

5 REPLIES 5
flying008
15 - Aurora

Hi, @Billibo418 

 

If you want to retain the last space, then remove the Trim funcion in Formula:

 

Trim(REGEX_Replace([Txt], "^(.+?\s)([[:alnum:]]+?)(\s.+)\2$", "$1$2$3"))

flying008_0-1670210913801.png

 

****

If it help you get your want output, please mark it as s solution and give a like for more share.

 

 

MarqueeCrew
20 - Arcturus
20 - Arcturus

@flying008 ,

 

getword([txt],1) is the second word.  

TrimRight([txt]," "+getword([txt],1)) should do the trick. 

cheers,

 

 mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
flying008
15 - Aurora

Hi, @MarqueeCrew 

 

Yep ! If have a string like "22 PO 4 AV LA 4" or want remove first repeat word, the RegEx will show flexible compatibility. 

KrishnaChithrathil
11 - Bolide

@Billibo418 

How about this?

 

KrishnaChithrathil_0-1670218645389.png

KrishnaChithrathil_1-1670218678807.png

KrishnaChithrathil_2-1670218738246.png

 

 

Billibo418
5 - Atom

flying008 : Works perfectly !

 

Thank you so much

 

Cheers,

Labels
Top Solution Authors