468,133 Members | 1,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

regex replace all non numerics with blank???

Hi I have a simple problem
hopefully. how would I replace all no numerics using <string name>.regex

if if I have a string like
123456.309.123456
or
123456-307-123456
or
123456 307 123456

all need to be nomalized to

123456307123456

so if

bn="123456-307-123456"
bn=bn.regex([0-9])

any ideas
Nov 17 '05 #1
2 10950
KH
string str = Regex.Replace( "19,*48bxwk674", @"\D", "" )
"rob merritt" wrote:
Hi I have a simple problem
hopefully. how would I replace all no numerics using <string name>.regex

if if I have a string like
123456.309.123456
or
123456-307-123456
or
123456 307 123456

all need to be nomalized to

123456307123456

so if

bn="123456-307-123456"
bn=bn.regex([0-9])

any ideas

Nov 17 '05 #2
Hello,

your idea was right but you forgot the leading ^ which means a negation of
your expression. So [^0-9]. But you can use the following, too:

string number = "123.456.344";
number = System.Text.RegularExpressions.Regex.Replace(numbe r, @"\D", "");
int real_number = Convert.ToInt16(number);

\D means all non-numeric chars are replaced by "".

Hope it helps.

Matthias
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by kids_pro | last post: by
1 post views Thread by GlennH | last post: by
9 posts views Thread by Whitless | last post: by
4 posts views Thread by Morgan Cheng | last post: by
2 posts views Thread by Jeremy | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.