473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 11211
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Stephane | last post by:
Hi, I'm trying to replace parenthesis using Regex.replace but I'm always having this error: System.ArgumentException: parsing ":-)" - Too many )'s. Parameter name: :-) Here's my code: ...
1
by: kids_pro | last post by:
Hi there, Is it possible to use RegEx.Replace to replace string like this. string str = "The world heavy weight match"; I want to replace world = w and match = m I can do that with 2 line of...
1
by: GlennH | last post by:
I am having trouble removing a pipe character using Regex.Replace - see the 2 NUnit tests below: The first replace works fine and the second Replace does not work. I've tried escaping the pipe...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
3
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
9
by: Whitless | last post by:
Okay I am ready to pull what little hair I have left out. I pass the function below my String to search, my find string (a regular expression) and my replace string (another regular expression)....
4
by: Morgan Cheng | last post by:
In my case, I have to remove any line containing "0.000000" from input string. In below case, it takes about 100 ms for 2k size input string. Regex.Replace(inputString, ".*0\\.000000.*\n", ""); I...
2
by: Jeremy | last post by:
I am trying to replace a string "P" with "\P" as long as the string "P" does not already have a "\" in front. for my search string I've used @"(P)" so my regex replace statement is: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.