Extract text from Text file using Substring

Hi All,

I am trying to do PDF Data extraction for some reasons with PDF I am not able to extract PDF correct so I extracted the desired text to the Text file from there I need to read the text and extract some values (around 5-10 )and assign each of them to variables.

How to approach this scenario? Using string manipulation or substring can anyone help with an example?

Sample data in the file looks like below
Name: Mirta Rodriguez
ABN: 79910XXX785

1 Like


you can use regex to achieve this , please refer below link



you can use Matches activity

To Extract Name (?<=Name:).*
To Extract Address (?<=Address:)(.|\n)*(?=\n)
To Extract ABN (?<=ABN:).*



Thanks for the reply

I tried using the above to extract the values from the textile but I am getting null values.(Tried writing it to file ) and got the Object reference not set to an instance of an object.Null exception error

Tried using the Regex tester and saw it shows zero matches.

Am I missing anything here

1 Like

It’s matching right?
What’s the issue here?
Check for every Value if it’s matching or not.


Sorry, My bad now cleared It matched.

Once this value is assigned to the collection variable from there If I want to assign to the variable I need to use foreach and assign to each variable right ?

Ex:- Name = CollectedData(0).ToString

Is this the correct approach

1 Like

Happy Learning

@Pradeep_Shiv Thanks for the ton for the above Regex samples, understood it quickly and tried using it for the rest of my fields and all worked fine except a few.

1 Like

Let me know, if you still face any issues

Sure, one issue my text file has values that are a combination of two variables. VarA + VarB

My file looks like something below.

Here I am trying to get a driver’s license, but It has a continuation of one more header which is the start of the second variable value .

Name: Mirta Rodriguez
ABN: 79910196785
Mobile No: 0413406671
Personal Email: mrcoaching26@gmail.com
Date of Birth: 16/10/1962
Driver’s Licence: 3184dsAccount No: 13287726
Introducing Dealer: Peter WarTen Toyota
Type: Toyota Access Business Vehicle Loan
Payment Required: $1,245.50
Contract Inception Date: 24 December 2018
Date Last Paid: 1 July 2020 Amount Last Paid: $410.25
Next Due Date: 22 October 2020 Next Payment Amount: $410.25
Arrears F/Fee Next Due: Arrears F/Fee Amount: $25.00
Instructions Issued Before?: No
Mortgaged Vehicle: 2018 TOYOTA YARIS
Colour: WHITE
Rego No: DZW63Q
Engine No: 2NZ8751771
VIN: JTDKW3D3801001503
Repo Allowed: Yes
Payout Amount: $17,722.06, available to 1 October 2020
Default Notice Dated: 7 August 2020
Expired On: 10 September 2020
Amount Due on Notice: $785.25.

any way while combining my second variable it will create in new line instead?

Thanks, Sorry for the long post.

1 Like

Hi @Pavan_Srikar,

I hope this helps

(?<=Driver’s Licence:).*(?=Account)


1 Like

Thanks for the help most of my work is done with the above example.

Once again thanks for the help :slight_smile:

Great learning and understanding today.

1 Like

Happy Learning

Hi @Pradeep_Shiv

Sorry to post this here

When I am trying to Set text into a column in one job portal .instead of variable name if I give hardcode values it is not giving any error.

If I Give a variable name I am getting the below error.

Source: Name (Name) (It is a variable name that has a value assigned from matches activity)

Message: Error HRESULT E_FAIL has been returned from a call to a COM component.

Exception Type: UiPath.Core.ElementOperationException

RemoteException wrapping UiPath.Core.ElementOperationException: Error HRESULT E_FAIL has been returned from a call to a COM component. —> RemoteException wrapping System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
at UiPath.UiNodeClass.Set(String bstrAttr, Object vValue)
at UiPath.Core.UiElement.Set(String attribute, Object value)
— End of inner exception stack trace —

Yesterday did the same code and got no errors ,this one was coming in the newly created code.

1 Like

Can you try using Type Into?
This is because of Browser issue or you can try Re-Installing Extension and try in IE or Edge

1 Like

Will try using Type Into.
Currently using the IE browser only.

1 Like

Check with Chrome,

Hi @Pradeep_Shiv

Can you help on below extraction in for regex the below string I am trying to extract in 3 different variables .

Mortgaged Vehicle: 2018 TOYOTA YARIS
Mortgaged Vehicle: 0000 ABCDEF GHIJKL

I tried and extracted the 2018 but for rest two I am unable to fetch

I used (?<=Mortgaged Vehicle:\s).[0-9]* for 2018 it was fine

Thank you

1 Like

hi @Pavan_Srikar …Here you go…

Variable 1= YourRegexvariable0).groups(1).tostring
Variable 2= YourRegexvariable0).groups(2).tostring
Variable 3= YourRegexvariable0).groups(3).tostring

Please check this post where you find the sample xaml similar to yours to handle the groups…

1 Like

(?<=Mortgaged Vehicle:\s).*