Extract PDF text using Regex

Hi Community!

I am new to Regex.
I read a PDF and output a string variable ‘text’.
I am trying to capture what comes after FROM: which are 3 lines followed by SUBJECT:. Example below.
ex. FROM: James Bond
Associate Director, C Team
Office of Towers

I’d like to capture the first line ‘FROM: James Bond’
Assigned James Bond as string variable ABC

I have Regex as
ABC= System.Text.RegularExpressions.Regex.Match( text, “(?<=FROM: ).*(?=SUBJECT:)”).value

The output is blank. Please help. Thank you!

@Jessica_Moseley ,

Check this regex101: build, test, and debug regex

the . is expressing every character except line break.

for getting text spanning over multiple line we can do:

for James Bond only we can do (optional trim the value afterwards)

Thanks, this worked!

system.text.regularexpressions.regex.match(text, “(?<=FROM:).*”).value

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