?
Solved

RegEx remove numbers from string

Posted on 2005-03-18
7
Medium Priority
?
375 Views
Last Modified: 2011-10-03
Hi All!

How can I remove all numbers and groups of numbers in a string and insert a replacement, say " digit "?

My regular expression reads...
Dim r As New System.Text.RegularExpressions.Regex("[0-9]*")

For a string ";th2345is;0i43s" I should get ";this;is"
But when I build the resulting string I get digit ;th digit digit is; digit i digit  digit s digit

Any help is appreciated.
Maru
0
Comment
Question by:yoshiman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 13578853
I don't understand, because it sounds like you are getting what you specified... replace each number or group of numbers with " digit "
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 13578928
Sorry, I misunderstood.  You want to match one or more occurances, using + instead of zero or more with *

Text = r.Replace(Text, "[0-9]+", " digit ")
Debug.WriteLine(Text)
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 13578935
To get ";this;is"

Text = r.Replace(Text, "[0-9]+", "")
Debug.WriteLine(Text)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yoshiman
ID: 13578965
Thanks for the reply!

No it's replacing it at almost evey turn unfortunately.
0
 

Author Comment

by:yoshiman
ID: 13578994
Paul,

Awesome.  Worked perfectly.
I need to read up a bit on reg exs i guess.  

Thanks so much!
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 13579016
Glad to help.  Thanks for the points, and I hope you have a good weekend.  :)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 13579072
Here's a great page that may help you.  I refer to it often, because the pattern documentation is buried deep in the .NET docs.:
http://regexlib.com/CheatSheet.htm
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question