?
Solved

RegEx remove numbers from string

Posted on 2005-03-18
7
Medium Priority
?
376 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

579 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