Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search with regular expression to remove zeros

Posted on 2010-08-26
6
Medium Priority
?
250 Views
Last Modified: 2012-08-13
I am a newb when it comes to regular expressions and looking for an answer.

I have a list of 8000 files... some have leading zeros, some do not... example

080-000411-2009
090-001144-2010
52-011-2009

I want to remove all leading zeros in both the first section and second... but leave the year alone... is this possible?

(I'm looking to do a find and replace in notepad++ using an expression)
0
Comment
Question by:hzrdc2
6 Comments
 
LVL 1

Accepted Solution

by:
snoy earned 668 total points
ID: 33533298
Hi,

Do this :
First : Remove the first 0 (Ctrl+H) :
$0
Replace "" [Leave blank]
Do it again if there is some number which starts with 00 then they will be fixed.
Second : Remove The 0 after there - (Ctrl+H) :
$-0
Replace "-"

Enjoy!
H.Y.
www.w3consulting.ma
0
 
LVL 1

Expert Comment

by:snoy
ID: 33533320
0
 
LVL 12

Assisted Solution

by:FDiskWizard
FDiskWizard earned 668 total points
ID: 33533344
in Search and Replace dialog, make sure Regular Expression is checked.

Two methods, and I'm assuming a single zero at the beginning:

Find what: ^(0)(.*)$
Replace with: \2

Or simply:
Find what: ^(0)
Replace with: {BLANK,NOTHING...}

If multiple leading zeros:

Find: ^[0*]
Replace with: Nothing....
0
Technology Partners: 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!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33533348

Find:
    0+(\d+-)0+(\d+-)(\d+)

Replace:
    \1\2\3

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 664 total points
ID: 33533358
Correction:
Find:
    0*(\d+-)0*(\d+-)(\d+)

Open in new window

0
 

Author Closing Comment

by:hzrdc2
ID: 33533498
This is why I love the internet... tried all three and they are all valid.

kudo's to you all... added to my knowledge today!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

783 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