How to extract every string in between different Delimeters

I have a string like this “mich.bommattrto@abc.com; Tom.Szski@abc.com; Chaterd.Andrs@abc.com” and I want to extract mich_Tom_Chaterd from this string.

This string contains 3 emails but there are strings that contains 1,2 or more than 3 emails.I want a generic solution

@faiqaqureshi90
have a look here:

String.Join("_",(Regex.Matches(strText,"(\.|\w)*?(?=\@)").Cast(Of Match).Select(Function (x) x.toString.Split("."c)(0))))

Ensure following:
grafik

Challenging it with missing dots:
grafik

Its Working
Can you please explain this?


Assign-0:
Str_Mails = “mich.bommattrto@abc.com; Tom.Szski@abc.com; Chaterd.Andrs@abc.com
Assign-1:
Str_Test = Str_Test + Split(Mail.Trim,“.”)(0) + “_”
Assign-2:
Str_Test = Str_Test.Substring(0,Str_Test.Length-1)

Regex - Regex101.com
grafik

With regex we do take all strings before the @ character
From all matches we do a split on the dot and take the first item
With String.Join we do surround the items with a “_”

1 Like

Thanks Alot
It really helped

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