princepawn has asked for the wisdom of the Perl Monks concerning the following question:
But I must insert $platform just before the dot-something, e.g.:.Z .zip .tar .ar
So I wrote this regexp (I have plenty of testosterone --- no wimpy split and join or rindex on '.' for me):solaris.Z linux_alpha.zip
So I think my regex is right. I am saying: be greedy and go all the way to the end of the string, but you must give up characters until the second parenthesized expression has been filled with a literal dot and at least one character after it. and therefore the second literal expression will have the file extension in it and I just need to pop $platform in between the two matched parts of the string.sub new_filename { my ($name,$platform) = @_; $name =~ /(.+)(\..+)$/ or die "$name is an invalid patch name"; "$1$platform$2"; }
But am I really right? Or have my gonads gotten the best of me?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex to match a literal dot near end of string
by japhy (Canon) on Jul 18, 2001 at 20:43 UTC | |
|
Re: regex to match a literal dot near end of string
by mdillon (Priest) on Jul 18, 2001 at 20:35 UTC | |
|
Re: regex to match a literal dot near end of string
by adamsj (Hermit) on Jul 18, 2001 at 20:39 UTC | |
|
Re: regex to match a literal dot near end of string
by scain (Curate) on Jul 18, 2001 at 20:34 UTC | |
|
(Elbie) Re: regex to match a literal dot near end of string
by elbie (Curate) on Jul 19, 2001 at 00:03 UTC | |
|
Re: regex to match a literal dot near end of string
by MZSanford (Curate) on Jul 18, 2001 at 20:35 UTC | |
by japhy (Canon) on Jul 18, 2001 at 20:39 UTC | |
by MZSanford (Curate) on Jul 18, 2001 at 20:43 UTC |