Query on REGEX expression

Hi,

As given below, My string consists of Where the third line is “Address 1” which is static, and the 2nd line is an empty blank line, and the first-line consists of a name.

Gautam Tarun

Address 1

I need the name above the “Address 1”, What will be the Regex Expression for it??

Thanks in advance !!!

@Rakesh_Sampath could you tell me, whatever you have explained is that in pdf format or anything else?

Yes, its a output string from a Read pdf text activity

@Rakesh_Sampath Then use only the anchor base activity . You will get an output as you expect.

1 Like

Hi @Vrushali_Gave

Yes you are right, But i need a Regex expression to extract.

Hi Rakesh,
Please find the below Regex code to get the desired output.

System.Text.RegularExpressions.Regex.Replace(sample_string,“[\n\r].*”,“”)

Let me know if it works :slightly_smiling_face:

Hi @elina
Thanks for your reply

The scenario is where, The example string i mentioned above is a part of a big string, That name is not the first line of that whole string, I need to map that Name using the static “Address 1” Keyword.

Hi Rakesh,
So you need the string which is before “Address 1” Keyword. Please correct me if I am wrong.

Exactly !! @elina

Hi Rakesh,
Please use the below code
sample_string.Substring(0,sample_string.IndexOf(“Address 1”)).Trim

Hi @elina

The above code, you mentioned takes all lines above “Address 1”, my expected output is Gautam Tarun

Hi @Rakesh_Sampath
If you want to differentiate Name with address then You can do this way…
1st extract the whole pdf text which provides you with both name and address. then
if you want Name alone you can split the both parts by using this code:
YourString.Split(Environment.NewLine.ToArray,StringSplitOptions.RemoveEmptyEntries)
it gives you 2 strings one with Name and other with Address you can use any based on your requirement. Let me know if it is helpful :slight_smile:

1 Like

Hi @NIVED_NAMBIAR

I tried this already, But the Expected output was inconsistent, So only i liked to ask you guys, to find out whether any other best way available to grab it !!

Hello @Rakesh_Sampath,

you can try this “(.*\n){2}(Address 1)” this will give you like below snap

image

Now you can split into New line and get the Name.

Cheers
@Rakesh_Sampath

1 Like

Hi @Rakesh_Sampath

Try this regex below

Hope it helps you

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

1 Like

Hi @Rakesh_Sampath,

image

I Hope this helpsRegex.xaml (5.1 KB)

Cheers
@Rakesh_Sampath

3 Likes

Thanks @Pradeep_Shiv @NIVED_NAMBIAR :innocent:

2 Likes

Happy learning,
Cheers
@Rakesh_Sampath

1 Like

Have a good learning

Happy new year :tada: @Rakesh_Sampath

1 Like

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