Splitting string and extracting a 9 character substring

Hi All,

I have to extract a 9 letter code from a string - the delimiter is quoate marks " - how do I use quote (") as a delimeter? I have the added complication that the code will be the 2nd instance that " appears

Sample text im extracting from below:
Your entry, named “test_entry”, has successfully been created with the reference “XXXXXXXXX”.
You can now access the return in the draft area.

I need to extract the XXXXXXXXX

Many thanks in advance for the help

@calOn8
You can do string.Split(""""c)(3) on the line to get the reference number. The Split function uses 4 " characters. The first and last are the start and end of the string and the two in the middle are used to escape the character and tell UiPath to literally use ".

Your array is then
0 - Your entry, named
1 - test_entry
2 - , has successfully been created with the reference
3 - XXXXXXXXX
4 - .

1 Like

Hi @calOn8,

Use regex pattern to get the data

(?<=\").*?(?=\")

If exactly 9 char use below

(?<=\").{9}(?=\")

Regards,
Arivu

it is not working

@Vashisht Can you be more specific?

The solution which gave is not working,it is returning the whole string

If the other string which is of length 9 is also quoted.
Please dont get me wrong, i said because he mentioned the second quoted string is required.

Yes second quote and given condition is 9 degits rights so you can use the above regex pattern. @Vashisht

Regards,
Arivu

Hello @calOn8,
Try this Regex. ...{9}$

  1. Use String Matches activity
  2. Insert the above Regex
  3. The result [outString(0)] should return the string within the second quote.

Regex Builder

1 Like

Hi @calOn8

If you only want to get the XXXXXXXXX between ",

Please try this regex and see if it’s what you need.

\s"([^\s]+)"

It will return Group 1 contain only XXXXXXXXX, so even if you have more than 9 or less than 9 digits, it should still works.

Cheers

Hi arivu96,

Thanks for that - however im worried that your solution may match to other 9 character words within the text.
For example, if “test_entry” was “Testentry”, then it would match to this first rather than the XXXXXXXXX code

Hi Dan this worked pretty flawlessly for myself - I can guarantee that the 4th (Row(3)) entry in the array will be the XXXXXXXXX code.

Thanks for the help!

1 Like

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