How to get text from string with reference of specific text

Hello,

I want to fetch the text from string with reference of specific text.
Ex. Below is my string and want to get one by one text like Supplier after colon, Supplier No, Amount and stored in variable.

Your action is required for following supplier invoice.
Supplier: 00001234 - ABC Supplier No.: 00001234
Amount: 123.45 Invoice No.: 123456789
Blocking Code: NP

Company Number: 456
Transaction Id: 123451234512345
Invoice Date: 2022-12-20T00:00:00-08:00
Invoice Due Date: 2023-02-18T00:00:00-08:00
Invoice Total Amount: 520.45
Invoice Currency: EUR
Invoice Amount USD: 535.88

I tried with below activity which gives me correct string output and from the same output want to fetch data.

image

Hey @nilesh.mahajan

You can use Regex with a Lookahead to Anchor onto some text. Like this Text Anchor example.

Just paste the values into the brackets and you can do some basic ones. Always check your results.

To use this in UiPath and get the 1st match only
Insert a new Assign activity and:
Assign Left:

INSERTxNEWxSTRINGxRESULTxVARIABLE

Assign Right:

system.Text.RegularExpressions.Regex.Match(INSERTxINPUTxSTRINGxVARIABLE, “INSERTxREGEXxPATTERN”).ToString

Regex Language Basics:
image
Quantifiers
image

Learn Regex with my MegaPost

Hopefully this helps :blush:

Cheers

Steve

Hi @nilesh.mahajan,

Check the attached workflow, based on the config and input text it does the job. Even you can have multiple param to extract single string/
ExtractString.zip (9.4 KB)

Hello @nilesh.mahajan
Try this

  1. Read the String Stored as YourString
  2. Use assing below with string Variable
System.Text.RegularExpressions.Regex.match(YourString,"(?<=Supplier:).*(?=Supplier)").ToString.Trim     ----> 00001234 - VERSTEIJNEN LOGISTICS KFT 

System.Text.RegularExpressions.Regex.match(YourString,"(?<=Supplier No.:).*(?=\nAmount:)").ToString.Trim  ----> 00001234

System.Text.RegularExpressions.Regex.match(YourString,"(?<=Amount:).*(?=Invoice No.:)").ToString.Trim     --->520.45

HI @nilesh.mahajan

Checkout the pattern

System.Text.RegularExpressions.Regex.match(YourStringvar,"(?<=Supplier:\s).*(?=Supplier)").ToString.Trim

System.Text.RegularExpressions.Regex.match(YourStringvar,"(?<=Supplier\sNo.:\s).*").ToString.Trim

System.Text.RegularExpressions.Regex.match(YourStringvar,"(?<=Amount:\s).*(?=\sInvoice No)").ToString.Trim

Hope this helps

Regards
Sudharsan

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