Extract Text between two fixed keywords

I have certain text to be extracted between two fixed set of labels. I tried some methods given but I was not able to do achieve the result what I want.(might be I ma missing something).
In the below text, I would like to extract the text between labels “Contact Details” and
Shipping Details

If you ordered an eBook you will receive a separate email with a registration key and instructions for accessing your eBook.

Contact Details
Name: ABC
Company Name:
Country: 12333
Address: XYZZZ
City: fdfd
State : sdsdsds
Postcode: 4343
Email: abc@gmail.com
Phone: +12344566

Shipping Details
Name: ABC
Company Name:
Country: XYZ
Shipping Address: AAAAAAA
City: dsds
State : dsds
Postcode: dsds

Please note that your order reference number is 232-3.

I thought of using in string , finding the index of contact details and then doing sub-string to extract the required text.
But I am not able to identify how to do in-string.
Is there any better method to perform the above operation.

Kindly help.


Hi you can use regex to get all the text between two specified words.

@Heena_Saini Welcome to uipath community.

You can use regex (Regular Expression) to get the result.

Try this one

@Heena_Saini you can use the below REGEX to obtain all the info between those two words:

system.Text.RegularExpressions.Match(yourtextstringhere,“(?<=Contact Details)(.*)(?=Shipping Details)”).value

If I understood well,below you can find my solution:
1.Store your String into a variable (ex:test_str)
2.test_str.Split({“Contact Details”,“Shipping Details”},StringSplitOptions.None)(1).Trim
You break the whole string after Contact Details and Shipping Details and access position 1 from the result and finnaly delete spaces using .Trim

Hope to help you.


RegexBTWtwoStrings.zip (1.8 KB)

outputStr=Regex.Match(inputStr, “(?<=Contact Details)([\S\s]*)(?=Shipping Details)”).Value



Thank You, this is working. It helped.

1 Like

Thank you for the suggestion

Awesome that it worked! :grinning::dizzy: @Heena_Saini

1 Like

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