Need help finding a regex pattern for extracting a data from a data string

I am trying to extract the phone number and full name from a data string, but I can’t figure out a regex pattern needed for extracting the said data, can anyone help me with it

This is the data string:
screenshot

FYI, I found a regex pattern to extract email and it worked.

([a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9_-]+)

btw The tool I use to extract this data only supports positive lookahead regex patterns

Hello

Got a sample?

In the meantime try this pattern for the Name.

And this for the phone.

1 Like

Hi @Fahad_Sheji ,
Instead of regex, I would have split the entire dataset on the newline character. This would present a String array with all the characters of a line in each array items.
I would then parse through each of the array items, and try to split the items with ‘|’, since I don’t see the | being used anywere else. Once split I would check to see if my split actually worked and whether the resulting array has 3 items - i.e. Name, Email and Number.
Once this is done, I would get the 0th position as the Name and the 2nd position element as the number.

This would work depending on the size of your dataset, and whether the | symbol is present anywhere else

But for regex, I think this should suffice -
([\w|\s]+|[a-zA-Z0-9.-]+@[a-zA-Z0-9. -]+.[a-zA-Z0-9_-]+|\d*)
image

Let me know if this works for you

Thanks,
Nishant

1 Like

Hey, I am quite new to this so not sure how to split the data in the integration tool I use.

Anyways I tried the regex pattern you gave me and it brought in the name of the firm instead of the data we needed.


I’ll add the whole data string for better reference, The highlighted one is what the regex brought in.

Anyways I know it’s hard to locate it without a header, so I looked into the HTML version of the email and it had proper headers before the data such as first name, last name, phone, etc but had the HTML code between, can we easily extract from that? this is the photo
call
first name

Hi @Fahad_Sheji

How about the expression?

To get Phone Number

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\|\s)\d{8,}").Tostring

To Get the Name

System.Text.RegularExpressions.Regex.Match(YourString,"^[^\|\*]+(?=\|)").Tostring

Regards
Gokul

Hello @Fahad_Sheji , Kind;y try this Regex pattern
For Name

System.Text.RegularExpressions.Regex.Match(YourString,"^\S+(?=\s\|)").ToString.Trim

image

For Number

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\|\s)\d+").ToString.Trim

1 Like