Solved

Search with regular expression to remove zeros

Posted on 2010-08-26
6
240 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 74

Expert Comment

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

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

Replace:
    \1\2\3

Open in new window

0
 
LVL 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now