How to get specific words from a string

Hi, guys!

I’ve an issue. How could I get these words in bold from this text below?

FullData = Nome Livro_Numero Livro_4.pdf|AA33|33|Nascimento|Planetario|Digitado|Numero ultima folha|2009|Ano final|Registros por folha|1|01

With this extracted data, I want to create a new variable to store it. I know I could use split or substring method, but I’m stucked on how could I use these “|” as markers. Like “the first data to get is 2 “|” from this position…”

Thanks in advance

@Caio_Dultra
based on the pattern L=Letter, D=Digit LLDD, DD, DDDD A regex can help

([A-Z]{2}\d{2})|(\d{2,4})

2 Likes

I’ll try it @ppr. Thank you!
“|” in REGEX means “Either or”, right? It’s like “if it doesn’t work, try this one”, isn’t it?

@Caio_Dultra
yes the | is like a OR operator to the different patterns

2 Likes

Nice! I’ll try it. Thank you again!

Man, it’s great but I think it’s not gonna work cause some of those data, like the first one can get out of this pattern and come “AAAA456”, for example. What about substring or split method?

can we see possible scenarios of expected output?
@Caio_Dultra

1 Like

Sure! @Pradeep_Shiv

After this: Nome Livro_Numero Livro_4.pdf| AA33 | 33 |Nascimento|Planetario|Digitado|Numero ultima folha| 2009 |Ano final|Registros por folha|1| 01

I need another variable like: ID = Data1 + Data2 + Data3 + Data4
ID = AA3333200901

@Caio_Dultra
Yes, this would be the best to share all requirements, patterns with us. However feel free to play with the pattern on the regex101 website.

AAAA456 can be covered by tuning the occurences ([A-Z]{2,4}\d{2,4})|(\d{2,4})

2 Likes

@Caio_Dultra, If your format is fix then Split can be best fit in your case. Once you get string array you can access any element based using index. You can pick specific elements and concate as needed.

Cheers :slight_smile:

2 Likes

Gotcha!
So, something like VarX.Split(“|”)?

1 Like

@Caio_Dultra
VarX.Split(“|”c)
Find a demo here: Caio_Dultra.xaml (6.8 KB)

3 Likes

@ppr

Which package should I install to solve it? I’ve tried many but nothing happened.

ensure that you have downloaded the xaml into your uipath project and open it from there

2 Likes

Thank you!

Now I’ve an issue. I saw that you used Add to Collection Activity but Matches Activity returns a collection too and you’ve also used regex. Can I use Matches without split method?

I dont get you, but if my xaml is running at your end you can decide which approach you want to use. I guess we have different approaches so 1 is not 100% compatible to the other. but can be adopted.

1 Like

Great!
It’s working flawless. Thank you :slight_smile:

Perfect, happy automation :+1:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.