Alteryx Designer Desktop Discussions

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

Replace string from the right

Saravanan13
8 - Asteroid

 

Hello,

 

I am working on a data extract from PDF. Since most of the PDF's are handwritten, Actual issue is the parenthesis bracket "(" is extracted as "c" in 5 out of 10 cases.

 

Below are the conditions:

 

1. If the country is China or Hong Kong then the last digit should be enclosed with a bracket. "()"

2. For countries other than  China or Hong Kong there will be no changes.

3.If alphabet "c" exist in last few digits of the string then it should be replaced by bracket "("

 

Can anyone help on this.

 

 

TaxCountryUpdated Tax
R2456c1)ChinaR12456(1)
1234567Australia1234567
S234567c5)Hong KongS234567(5)
12345USA12345
A12456c1)ChinaA12456(1)
4 REPLIES 4
AndrewDMerrill
13 - Pulsar

Do you need more logic for #1? As far as the "c" is concerned:
REGEX_Replace([Tax], "(.*\d)(c)(\d.*)", "$1\($3")

in a Formula Tool should get the job done.

Qiu
20 - Arcturus
20 - Arcturus

@Saravanan13 

Parsing data from PDF can be very tricky I believe.
It would be better if you could provide a bigger dataset, so we can look for more variants.

Based on you curent criteria, we can first filter the "China" and "Hong Kong " first, then use the function "ReverseText" in order to replace the first occurent of "c".

1127-Saravanan13.PNG

flying008
14 - Magnetar

Hi, @Saravanan13 

 

Maybe there is need more data to catch your situation.

 

IIF([Country] in ('China', 'Hong Kong'), REGEX_Replace([Tax], '(c)(\d+?.?)$', '\($2'), [Tax])

 

录制_2023_11_27_14_06_16_400.gif

Saravanan13
8 - Asteroid

Thank you so much. It worked.

Labels