Let’s talk Alteryx Copilot. Join the live AMA event to connect with the Alteryx team, ask questions, and hear how others are exploring what Copilot can do. Have Copilot questions? Ask here!
Start Free Trial

Alteryx Designer Desktop Discussions

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

Extract a specific text from a field

griseldagomes
8 - Asteroid

Hello Experts,

I am looking for a way to extract a specific text which starts with 'R1' followed by 6 characters (total character length = 8) from field 'Reference'.

unique no.Reference
1text 1 hello R14388AB
2dummy R19584PE
36548 R1T1258X test 
4checkfile R19865WW
5R1E9556S tester

 

Below is the expected output

unique no.Referenceoutput
1text 1 hello R14388ABR14388AB
2dummy R19584PER19584PE
36548 R1T1258X test R1T1258X
4checkfile R19865WWR19865WW
5R1E9556S testerR1E9556S

 

Can you please resolve this query.


Thank you

13 REPLIES 13
danilang
19 - Altair
19 - Altair

hi @griseldagomes 

 

you can use the following expression in a Regex tool set to parse 

.*?(R1.{6}).*

The capture group is (R1.{6}) which looks for the exact string R1 followed by any 6 characters

 

Dan

cjaneczko
13 - Pulsar

The following should work in a formula tool

 

REGEX_Replace([Reference], '.*\b(R1\S+).*', '$1')
flying008
15 - Aurora

Hi, @griseldagomes 

 

FYI.

(?:^|\s)(R\d+\S+)(?=\s|$)

 

录制_2024_01_16_09_40_12_354.gif

 

 

griseldagomes
8 - Asteroid

Thank you @danilang @cjaneczko @flying008 for taking time out to respond to my query.

Alpha325
6 - Meteoroid

Thanks @flying008

 

What about I want to drop "R1" as well and only keeps the number after that? Thanks. 

flying008
15 - Aurora

Hi, @Alpha325 

 

So, what about other letter like 'WW' or 'T' after drop 'R1' ? If you only want the number :

(?:R1\D?)(\d+)\S+(?=\s|$)

 

录制_2024_03_21_08_32_58_567.gif

Alpha325
6 - Meteoroid

Thank @flying008 I should have clarified more. Using this case as an example, I want to keep everything after "R" including numbers, special characters such as "-" till the next space in the content. Example could be - for example "R12515-52125-21521 Denver" and the length could vary. And I only want to carve out "12515-52125-21521". Thanks!

flying008
15 - Aurora

录制_2024_03_21_10_34_19_801.gif

Alpha325
6 - Meteoroid

Thanks @flying008. This helps a lot. But for some reason, when I run it, it always missed /dropped the very last digit. Do you know why? Thx. 

Labels
Top Solution Authors