Extracting Specific Text from a Text File

Need help on this.

I already use Read PDF Text and output it to a text file shown below.
I need to extract

  1. the name (in this case it’s TAN AH KOW) but this name is different for different letters and also different lengths.
  2. the date (in this case it is 16 Nov 2022 but will be different for different letters)

How can I do that?

Here is the content of the text file:

Ref NO: 1234 5678

Oct 18, 2022

TAN AH KOW
Senior Supervisor
ABC COMPANY

Dear member,

ACCOUNT

We checked your account, and $100 had already been credited to your account on 16 Nov 2022. You may refer to the attached bank statement for more information.

HI @ayeo22

In the text whether Senior Supervisor is the static one

If yes you can try with this regex expression

System.Text.RegularExpressions.Regex.Match(YourString,"\S.*(?=\nSenior\sSupervisor)").Tostring

Output -> TAN AH KOW

image

Regards
Gokul

Thanks for the prompt reply.
Unfortunately, the Senior Supervisor is also not static, can be Manager, Senior Manager, etc.

Date output I need the 16 Nov 2022 which is always in the same location

HI @ayeo22

For Date you can try with this expression

System.Text.RegularExpressions.Regex.Match(YourString,"\b\d{2}\s\S{3}\s\d{4}\b").Tostring

Output ->16 Nov 2022

image

HI @ayeo22

You can try with this expression for Name

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\b\S{3}\s\d{2},\s\d{4}\b\n\n)\S.*").Tostring

Output -> TAN AH KOW

image

Hello @ayeo22
Try this
To get date

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=account\son\W)[\dA-Za-z\s]+").Tostring.trim

To get Name

System.Text.RegularExpressions.Regex.Match(YourString,".*(?=\WSenior\WSupervisor)").Tostring.trim

Thanks, I will come back tomorrow after trying this.
Need to settle something urgent now.

Thanks again

try this

System.Text.RegularExpressions.Regex.Match(YourString,".*(?=\WSenior\WSupervisor)|.*(?=\WSenior\WManager)|.*(?=\nManager)").Tostring.trim

There could be many different positions besides Senior Supervisor, Manager and Senior Manager.
Hope this works for no matter what position it is

Have you tried with this expression ? @ayeo22

Sorry, I have to try tomorrow and let you know

Forgot to mention that the Name can also be of different lengths for different members e.g. Mohammed Subramaniam bin Ashok Kumar, etc.

This will also extracted by this expression

image

Kindly check this and let me know the status @ayeo22

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