Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 13th, 2013, 05:39 AM
dompter80 dompter80 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 dompter80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 40 sec
Reputation Power: 0
Perl Regular Expression: 0XX, 00X, XXX

hi, I would like to know if there is any regular expressions in Perl to search zeros at the start of a file name

I want to then replace these zeros

so

00x.jpg > x.jpg
0x0.jpg > x0.jpg
xxx.jpg > xxx.jpg
0xx.jpg > xx.jpg

Reply With Quote
  #2  
Old February 13th, 2013, 05:53 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,834 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 1 h 44 m 46 sec
Reputation Power: 811
Um,
Code:
/^0/

??

Reply With Quote
  #3  
Old February 13th, 2013, 06:00 AM
dompter80 dompter80 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 dompter80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 40 sec
Reputation Power: 0
doesn't work...

Reply With Quote
  #4  
Old February 13th, 2013, 06:03 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,834 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 1 h 44 m 46 sec
Reputation Power: 811
I love detailed error descriptions like that...

So what "doesn't work"? What's your code? What's your test case?

The regex I gave you matches a "0" at the beginning of the string. You still have to replace this match, of course.

Reply With Quote
  #5  
Old February 13th, 2013, 01:27 PM
dompter80 dompter80 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 dompter80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
I love detailed error descriptions like that...

So what "doesn't work"? What's your code? What's your test case?

The regex I gave you matches a "0" at the beginning of the string. You still have to replace this match, of course.


Sorry, I know nothing about Perl.. anyway, I found what I needed by trial and error (but thank you anyway):

(.*)-0*(.+)

Reply With Quote
  #6  
Old February 13th, 2013, 02:02 PM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,645 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 20 h 40 m 59 sec
Reputation Power: 1170
Original requirement/request:
Quote:
is any regular expressions in Perl to search zeros at the start of a file name


OP's solution:
Quote:
Originally Posted by dompter80
Sorry, I know nothing about Perl.. anyway, I found what I needed by trial and error (but thank you anyway):

(.*)-0*(.+)

That regex pattern doesn't meet the requirements that you specified you needed. It matches a 0 anywhere within the filename where it is preceded by a dash and followed by anything. In fact it's less precise than that; since the 0 is optional, it only has to match a dash and one or more other characters.

So, it would match this:

--

Last edited by FishMonger : February 13th, 2013 at 02:06 PM.

Reply With Quote
  #7  
Old February 14th, 2013, 05:18 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 502 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 18 h 50 m 40 sec
Reputation Power: 385
To remose all the 0's at the beginning of your string, try something like this:

Code:
$file_name =~ s/^0+//;


Which is basically the regex Jacques gave you in the first place, which just the full replacement syntax.

Reply With Quote
  #8  
Old February 14th, 2013, 06:54 AM
dompter80 dompter80 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 dompter80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by Laurent_R
To remose all the 0's at the beginning of your string, try something like this:

Code:
$file_name =~ s/^0+//;


Which is basically the regex Jacques gave you in the first place, which just the full replacement syntax.


thanks guys

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl Regular Expression: 0XX, 00X, XXX

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap