Hi Gary,
You have to edit your expression in order to do exactly what you are
looking for; after replacing any ones and zeroes as you have done, you
could easily perform a regex replace as the following one:
// ...
cleankey = Regex.Replace(cleankey, "[^a-zA-Z2-7]", String.Empty);
// ...
HTH
--
Efran Cobisi
http://www.cobisi.com
Gary Harpin wrote:
> Hello all,
>
> I am trying to use Regex.Replace() to clean a string before working on
> it.
>
> The incoming string can be of the form " 5E1Y - UMCF - PZNG - RPR4 -
> H4KF - 6ICJ - HQ " or "5E1Y:UMCF:PZNG" or ... and I need to replace any
> ones and zeros with Is and Os and the strip it of everything that is not
> A-Z or 2-7. "5EIYUMCFPZNGRPR4H4KF6ICJHQ"
>
> So far I do the following:
> ...
> cleankey = cleankey.Replace("1", "I").Replace("O", "0");
> cleankey = Regex.Replace(cleankey, @"-([A-Z2-7])*", "");
> ...
>
> The data will come from multiple sources (database, files, user input)
> so need to handle different encodings, the above code fails on the first
> stample because the last '-'.
>
> I don't understand regex that well and could do with a hand.
>
> Thank you.
>
> Regards,
> Gary Harpin
>
> ________________________________
>
> "...a computer is a stupid machine with the ability to do incredibly
> smart things, while computer programmers are smart people with the
> ability to do incredibly stupid things. They are, in short, a perfect
> match.." Bill Bryson
>
> [No Disclaimer]
>
>
> ===================================
> This list is hosted by DevelopMentorĀ® http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com