Re: regular expression to get a file extension

2002-04-11 Thread Ahmed Moustafa
> # foo.txt.bak => bak > ($extension) = $name =~ /.*\.([^.]*)/; > # or > # ($extension) = $name =~ /\.([^.]*)$/; It doesn't work if there is no extension in $name. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: regular expression to get a file extension

2002-04-11 Thread Jeff 'japhy' Pinyan
On Apr 11, Ahmed Moustafa said: >> # foo.txt.bak => bak >> ($extension) = $name =~ /.*\.([^.]*)/; >> # or >> # ($extension) = $name =~ /\.([^.]*)$/; > >It doesn't work if there is no extension in $name. Yes, and like I said in the post, if there is NO extension AT ALL (meaning no . at al

Re: regular expression to get a file extension

2002-04-09 Thread Jeff 'japhy' Pinyan
On Apr 9, Ahmed Moustafa said: >John W. Krahn wrote: >> Ahmed Moustafa wrote: >> >>>Jeff, thanks a lot for your explanation. I really appreciate it. >>> >>>Jeff 'Japhy' Pinyan wrote: >>> Please use File::Basename. Save us all the headache. >>>I was thinking that avoiding modules would

Re: regular expression to get a file extension

2002-04-09 Thread Jeff 'japhy' Pinyan
On Apr 9, Ahmed Moustafa said: >Jeff, thanks a lot for your explanation. I really appreciate it. > >Jeff 'Japhy' Pinyan wrote: >> Please use File::Basename. Save us all the headache. > >I was thinking that avoiding modules would make the code more portable. >Am I right? File::Basename is a STA

Re: regular expression to get a file extension

2002-04-09 Thread Ahmed Moustafa
John W. Krahn wrote: > Ahmed Moustafa wrote: > >>Jeff, thanks a lot for your explanation. I really appreciate it. >> >>Jeff 'Japhy' Pinyan wrote: >> >>>Please use File::Basename. Save us all the headache. >>> >>I was thinking that avoiding modules would make the code more portable. >>Am I right?

Re: regular expression to get a file extension

2002-04-09 Thread John W. Krahn
Ahmed Moustafa wrote: > > Jeff, thanks a lot for your explanation. I really appreciate it. > > Jeff 'Japhy' Pinyan wrote: > > Please use File::Basename. Save us all the headache. > > I was thinking that avoiding modules would make the code more portable. > Am I right? No, _using_ modules woul

Re: regular expression to get a file extension

2002-04-09 Thread Ahmed Moustafa
Jeff, thanks a lot for your explanation. I really appreciate it. Jeff 'Japhy' Pinyan wrote: > Please use File::Basename. Save us all the headache. I was thinking that avoiding modules would make the code more portable. Am I right? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional

RE: regular expression to get a file extension

2002-04-09 Thread Jeff 'japhy' Pinyan
On Apr 9, Jason Larson said: > $extension =~ s/(^.+\.?)([^\.]*)$/$2/; > >Your regex will fail for a couple of different reasons: [snip] Your regex will fail, too. Here's why... assuming $extension is "foobar.txt", here is how the regex matches: ^ matches the beginning of the string

RE: regular expression to get a file extension

2002-04-09 Thread Jason Larson
> -Original Message- > From: Ahmed Moustafa [mailto:[EMAIL PROTECTED]] > Subject: regular expression to get a file extension > > I had the following regular expression to get the extension > from a file > name: > > > $extension = $filename; > $extension =~ s/(^.+\.)([^\.]+)$/$2/; > >

Re: regular expression to get a file extension

2002-04-08 Thread John W. Krahn
Ahmed Moustafa wrote: > > I had the following regular expression to get the extension from a file > name: > > > $extension = $filename; > $extension =~ s/(^.+\.)([^\.]+)$/$2/; > > > But it didn't work (in case the $filename didn't have an extension); so > I had to add the following line: > >