How to get text starting from a word to end of the line

I have a PDF. I am reading PDF and storing to a variable.

Then I need to extract a string from a particular word(Eg: “Name:” ) to the end of the line. How can I do that?

Name: Rob Hines

Name: There is a dog walking on the street

I have to extract the entire text next to Name: till the end of the line

Hi!

You can use Regex
:owl: :bookmark: [CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

Here’s a suggestion for a regex expression:
(?<=Name:\s).*

Use this site to test it:
regex101: build, test, and debug regex

I tried the following but it’s throwing error. "Compiler error…Expression expected)

System.Text.RegularExpression.Regex.Match(?<=(e-name):\s).*)

You need to pass your expression as a string:

System.Text.RegularExpression.Regex.Match(“?<=(e-name):\s).*”)

I tried this too and it says “Compiler error” …Reference to a non-shared member requires an object reference

I’m sorry!

You need to pass both your expression and the string you want to use that regex expression on.

System.Text.RegularExpression.Regex.Match(“your text”, “your regex expression”)

It’s all explained in the link in my first post

Now it says "Cannot assign from type "system.Text.RegularExpression.Match’ to type “System.string” in Assign activity

Can you please provide me the entire expression?

System.Text.RegularExpression.Regex.Match(pdfOutput, “?<=(e-name):\s).*”)

System.Text.RegularExpression.Regex.Match(pdfOutput, “(?<=Name:\s).*”).Value

This is not giving me anything. its giving empty value.

System.Text.RegularExpression.Regex.Match(pdfOutput, “(?<=(e-name):\s).*”)

are there open and close brackets next to e-name causing any problems?

it is “(e-name):” not “e-name:”

Try this instead:

System.Text.RegularExpression.Regex.Match(pdfOutput, “(?<=\(e-name\):\s).*”)

1 Like

its now throws this exception -

Assign: parsing “(?<=(e-name\):\s).*” - Not enough )'s

You’re missing a \

image

image

thank you soo much, it worked.