Solved

Search with regular expression to remove zeros

Posted on 2010-08-26
6
243 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
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…

828 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