Need help to extract only characters from a string

Hi,

Eg : I have string value - 2M Fairview Hospital

From this string I would need to extract only characters like - M Fairview Hospital

I am using the attached regex format but, it’s giving me the null value…not sure why…Can anyone help me with this…

System.Text.RegularExpressions.Regex.Match(StrOrgname,“[A-Z a-z]*”).ToString

Thanks,
Divya.

Hi @divya.x.kuchi

How about this expression

System.Text.RegularExpressions.Regex.Match(YourString,"\D.*").Tostring

image

1 Like

Hi @divya.x.kuchi

Please use this regex \D.+

\D is for excluding numbers

cheers

This is the result @divya.x.kuchi

image

Regards
Gokul

You need to use .*

System.Text.RegularExpressions.Regex.Match(StrOrgname,“[A-Z a-z].*”).ToString

You can see the different in the image

Result

image

Regards
Gokul

Hi Gokul,

Thanks for the help. What expression should i use to match only numbers?

HI @divya.x.kuchi

System.Text.RegularExpressions.Regex.Match(StrOrgname,“\d+”).ToString

image

Hi,

FYI, because you use [A-Z a-z]* and it matches empty string just before 2. (* means 0 or more)
So [A-Z a-z]+ will work as you expect. (+ means 1 or more)

Regards,

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