Extract some set of strings from string

Hii,

suppose i have a string like:

Inbox number: ECH-12-G65 Extension number: 99

I want to extract only ECH-12-G65

Please help

Hi @Doonline,

If it will always come in this format, you can use it.

value = "Inbox number: ECH-12-G65 Extension number: 99"

inboxNumber= value.Split(":"c)(1).TrimStart.Split(" "c)(0)

Regards,
MY

Thank you so much @muhammedyuzuak learned something new

1 Like

You’re welcome, I’m happy.

can u help in one more case like this?

Of course.

  1. Inbox number ECH-12-G65

  2. Inbox number (2): PM2-17-G65

in first case this : is missing and in second (2) present but I want to extract ECH-12-G65 from 1st and PM2-17-G65 from second

System.Text.Regularexpressions.Regex.Match(Str_Value,"\w+-\d+-\w+$").Value

1 Like

Understood. If the format will change in this way, it is better to use regex.

Sadece sondaki $ işaretini kaldırabilirsiniz. Bence bu açıklamanın devamı var.

1 Like

This inbox number can be MD8s29812 in this format also. Mostly * will be present

Okay.I will try this method also

for 1 => inboxNumber = value.Split(" "c).Last.Trim
for 2 => inboxNumber = value.Split(":"c).Last.Trim

Regex maybe applied between two string expressions. If you share all possible situations, better solutions will be shared

There are only two situations

  1. Inbox number EC12/649GDMUe98G6505
    2)Inbox number (2): PM2
    17-G6587*GY/*02

image

What does means here ±

Can you explain given regex expression really appreciate you

Hi @Aleem_Khan,

I leave a link so you can learn the details and test it. You can access the explanation of the regex written using this page.

Regards,
MY

I have basic knowledge in regex I just want to learn some advance logic as you created above I believe if I can read the expression I definitely can write please help me for that.