The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Perl Regular Expression: 0XX, 00X, XXX
Discuss Perl Regular Expression: 0XX, 00X, XXX in the Perl Programming forum on Dev Shed. Perl Regular Expression: 0XX, 00X, XXX Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 13th, 2013, 05:39 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
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
|

February 13th, 2013, 05:53 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|

February 13th, 2013, 06:00 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 31 m 40 sec
Reputation Power: 0
|
|
doesn't work... 
|

February 13th, 2013, 06:03 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
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.
|

February 13th, 2013, 01:27 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
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*(.+)
|

February 13th, 2013, 02:02 PM
|
|
|
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.
|

February 14th, 2013, 05:18 AM
|
|
|
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.
|

February 14th, 2013, 06:54 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|