Extract two values using Regex

Hi All,

I have PDF files and I need to extract 2 values.

for example, Name and phone number.

I create a regex to extract these values as separate. because I need to use this in a different place separately.

my problem is, in some files, I have only one name and one number in another mabey I have 2 or 3, etc… so it is not fixed.

And I need to check if the name = “Any Name”, save the name in a variable and number in another variable.

I can do this if I have one name and number, but I get difficult because I need to create this dynamic.

Also, I can prin all value from regex but how I can use it if condition. I don’t want to use excel if there another way that will be better.

could anyone help me, please?

Thank you.

Is it possbile for you share one example PDF file and what regex you are using to extract name and number?

1 Like

sure

Name.txt (217 Bytes)

I read it from text file.

this the code:

for name:

(?<=\<name\>).+(?=\<\/name\>)

for number:

(?<=\<number\>).+(?=\<\/number\>)

I need number for Olive

Thank you

Use Matches activity from UiPath.System.Activities package. Use this activity twice. Once with name regex and second time with number regex. The output of this activity is a collection(with all matches found), you can create a variable in the output property by pressing cntrl+k. Now you have names collection and numbers collection.

You can iterate through names collection using for each loop. There’s an option to store Index value in the for each loop properties. Inside the body, if name = Olive, then you can get number by that index. If Numbers is the collection variable name and Index is the index variable name, then you can get by Numbers(Index)

Thank you @Surya_Narayana_Korivipadu I will check

Inside the body, if name = Olive, then you can get number by that index. If Numbers is the collection variable name and Index is the index variable name, then you can get by Numbers(Index)

could you please explain this more?

ok.

  1. Assume that you have saved outputs of your matches activities in variables called “Names” and “Numbers” respectively.
  2. For each name in Names, if name.tostring().equals(“Olive”), then you can get respective number with Numbers(Index). See below screenshot:

As you want number for Olive, you need to do this. Or else, for loop is not needed.

Hope this helps you. Let me know if you still have any doubts.

1 Like

Thank you @Surya_Narayana_Korivipadu for your help. it is working fine.

1 Like

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