473,379 Members | 1,260 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,379 software developers and data experts.

Regex: Retreive numbers out of string

Hello,

How would I retreive only the numbers out of a string?
Regex.Replace(mString, -Expression-, "")

eg: mString = "AZE|@#{1^2#{[^3ert/.?" should return '123'

TIA,

Michael
Nov 21 '05 #1
7 5061
=?Utf-8?B?TWljaGFlbCBNYWVz?= <mi*****@merlot.com> wrote in news:AA27B7B3-
75*************************@microsoft.com:
Hello,

How would I retreive only the numbers out of a string?
Regex.Replace(mString, -Expression-, "")

eg: mString = "AZE|@#{1^2#{[^3ert/.?" should return '123'

You can use [0-9]+ and loop through all the matches in the collection to
the rebuild the number.
Nov 21 '05 #2
Michael,
Define your expression so it matches on all not numeric characters. The
standard character class for digits is "\d", the standard character class
for non-digits is "\D".

Something like:

mString = "AZE|@#{1^2#{[^3ert/.?"
mString = Regex.Replace(mString, "\D", "")
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"Michael Maes" <mi*****@merlot.com> wrote in message
news:AA**********************************@microsof t.com...
Hello,

How would I retreive only the numbers out of a string?
Regex.Replace(mString, -Expression-, "")

eg: mString = "AZE|@#{1^2#{[^3ert/.?" should return '123'

TIA,

Michael

Nov 21 '05 #3
> the standard character class for non-digits is "\D".

Thank you Jay, I've been looking for "that one" parameter for over an hour -
obviously in the wrong places (also at http://www.regexlib.com but could find
it there neighter).

Sure helped,

Michael
Nov 21 '05 #4
> You can use [0-9]+ and loop through all the matches in the collection
to the rebuild the number.

Hi Anon, the thought had crossed my mind, but then I could have used the
String-Class.

Thanks, Michael
Nov 21 '05 #5
=?Utf-8?B?TWljaGFlbCBNYWVz?= <mi*****@merlot.com> wrote in
news:0E**********************************@microsof t.com:
> the standard character class for non-digits is "\D".


Thank you Jay, I've been looking for "that one" parameter for over an
hour - obviously in the wrong places (also at http://www.regexlib.com
but could find it there neighter).


I'm not sure if you have this link yet - but I found it very useful when it
comes to RegEx:

http://msdn.microsoft.com/library/de...l=/library/en-
us/cpguide/html/cpconCOMRegularExpressions.asp
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #6
Michael,
The MSDN link I gave includes the entire RegEx language supported by
System.Text.RegularExpressions namespace.

http://msdn.microsoft.com/library/de...geElements.asp

The other link I gave is a tutorial that includes the .NET RegEx syntax
along with other syntaxes.

Hope this helps
Jay

"Michael Maes" <mi*****@merlot.com> wrote in message
news:0E**********************************@microsof t.com...
> the standard character class for non-digits is "\D".


Thank you Jay, I've been looking for "that one" parameter for over an
hour -
obviously in the wrong places (also at http://www.regexlib.com but could
find
it there neighter).

Sure helped,

Michael

Nov 21 '05 #7
Hi Jay,

I think www.regular-expressions.info will be good to polish a bit my RegEx
Syntax knowledge (as if it existed :-))
Thanks again!
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
9
by: Tim Conner | last post by:
Is there a way to write a faster function ? public static bool IsNumber( char Value ) { if (Regex.IsMatch( Value.ToString(), @"^+$" )) { return true; } else return false; }
5
by: Tap | last post by:
I would like to parse the following string with as little code as possible. stringValue = "Email Message ID:TAPASVI to...
4
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
24
by: cassetti | last post by:
Here's the issue: I have roughly 20 MS excel spreadsheets, each row contains a record. These records were hand entered by people in call centers. The problem is, there can and are duplicate...
10
by: bullockbefriending bard | last post by:
first, regex part: I am new to regexes and have come up with the following expression: ((1|),(1|)/){5}(1|),(1|) to exactly match strings which look like this: 1,2/3,4/5,6/7,8/9,10/11,12 ...
13
by: brad | last post by:
Still learning C++. I'm writing some regex using boost. It works great. Only thing is... this code seems slow to me compared to equivelent Perl and Python. I'm sure I'm doing something incorrect....
3
by: Smokey Grindel | last post by:
Alright so I have a string... that can be anything like this then have a number like 102.34m, yes there is a m behind it to say "this is money", no I didn't design the spec thats just how data...
3
by: =?Utf-8?B?TWFya19C?= | last post by:
The following is working for me but I want to include numbers in scientific notation. public double Evaluate( string expr ) { const string Num = @"(\-?\d+\.?\d*|\-?\.\d+)" Regex reMulDiv = new...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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.