Regex with multiple underscore

Hello,

I am trying to extract the email id.

Text:
2dbccf5bc0de_327050.0670_sun_engineer@sun.com
4bb1-a91d-23bd336d7b1e_362833.0120_Steffi.Gill@kjhk-one.de

My expression to split is:
Mystring.ToString.Split("_"c)(1).ToString

It works for the second one but not for the first one as I only get sun as an output.

I tried Regex : “[a-zA-Z0-9-.]+@[a-zA-Z-]+.[a-z]{2,}”
but I get only “engineer@sun.com”.

How can it work for both the expression.

Hi @parnalmahavir.patni

Try this

(?<=\d+_).*

Regards,

Hi @parnalmahavir.patni

(?<=\_)[A-Za-z]+.*

@parnalmahavir.patni

System.Text.RegularExpressions.Regex.Match(Input,"(?<=\d+_).*").Value

Regards,

It shows error
Assign: Invalid pattern ‘(?<=_)[A-Za-z]+.*’ at offset 6. Unrecognized escape sequence \_.

Hi @parnalmahavir.patni

Can you try the below regular expression:

System.Text.RegularExpressions.Regex.Match(Input,"(?<=\d+_)[a-zA-Z0-9-._]+@[a-zA-Z-]+.[a-z]{2,}").Value.Trim()

The image shows a code debugging window with regular expression matches for two email addresses extracted from strings. (Captioned by AI)

Regards

@parnalmahavir.patni

How about the following?

((?<=\d{4,}_)[A-Za-z]+.*)

Regards,

1 Like

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