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

regex to remove leading zeros and hypens?

I basically need to remove any leading zeros and hyphens from a string...
regex seemed like the best rout and using a replace regex method... anyone
know of any good strings for this? The one I just made quick is ^0+|[-] but
not having much experience with regex, is this the correct one?

Nov 10 '08 #1
2 10609
Smokey Grindel wrote:
I basically need to remove any leading zeros and hyphens from a
string... regex seemed like the best rout and using a replace regex
method... anyone know of any good strings for this? The one I just made
quick is ^0+|[-] but not having much experience with regex, is this the
correct one?
I would make a set that matches either a zero or a hyphen:

^[0\-]+

That could be used to replace this:

0--000-----0hello

into:

hello

Perhaps you want it to be more specific, like removing an optional
single hyphen followed by any number of zeroes?

^-?0*

This could be used to replace this:

-00001123

into:

1123

but it would leave this:

-00----00000Hi

as:

----00000Hi

--
Göran Andersson
_____
http://www.guffa.com
Nov 10 '08 #2
"Smokey Grindel" <no****@nospam.comwrote in message
news:eo**************@TK2MSFTNGP06.phx.gbl...
>I basically need to remove any leading zeros and hyphens from a string...
regex seemed like the best rout and using a replace regex method... anyone
know of any good strings for this? The one I just made quick is ^0+|[-] but
not having much experience with regex, is this the correct one?
Your query is somewhat light on specifics, but if you have strictly leading
zeros and hyphens I think I would use String.TrimStart. That strikes me as
more straightforward than a regex replace. But if you want to play with
regex expressions get Expresso from UltraPico. It's free.

Bob
Nov 10 '08 #3

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

Similar topics

5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
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...
2
by: Brian Henry | last post by:
Hi everyone, I never have worked much with regex (trying to learn it now myself) but I have a simple problem that I need to solve.. Say I have numbers like this 00023432-234...
2
by: chris | last post by:
Hi, I have a simple ms access application that allows you to scan barcodes in to a form which stores them in the database. The barcodes are 6 digits in length e.g. 555666 but my handheld...
4
by: skavan | last post by:
Use Case: We have music files that describe, in their filename, attributes of the music. We do not know a general pattern that applies to all filenames -- but we do know that filenames that are...
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
6
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for...
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
5
n8kindt
by: n8kindt | last post by:
First of all, i haven't been to this site in a while and WOW is it much improved. I love all the new stuff--it looks great! I am all but done building a simple Point of Sale system through...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.