Solved

Search with regular expression to remove zeros

Posted on 2010-08-26
6
242 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 167 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 167 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 166 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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…

786 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