![]() |
|
Pathologically Eclectic Rubbish Lister | |
PerlMonks |
positive look behind regexp mysteryby rovf (Priest) |
on Aug 01, 2008 at 08:17 UTC ( #701618=perlquestion: print w/replies, xml ) | Need Help?? |
rovf has asked for the wisdom of the Perl Monks concerning the following question: I wanted to substitute the extension of a filename by 'txt', that is to transform abc/xyz.something into abc/xyz.txt. This is easy, but maybe driven by the sudden thought that I'm becoming an old man as the years passed by without ever having tried a positive look behind regexp, I came up with the following silly solution: That is, substitute the longest string at the end of the filename which does not contain a period, but is preceded with one. Interestingly, this did not work - no substitution was taking place. In my case this is overkill, because I happen to know in my filename that there *is* a period, so I could have much easier written (this would however replace the complete filename with txt if it doesn't contain a period). Nevertheless I would like to know *why* my original solution has failed. Any suggestions?
-- Ronald Fischer <ynnor@mm.st>
Back to
Seekers of Perl Wisdom
|
|