Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!ames!lll-winken!uunet!yale!Duchier-Denys From: Duchier-Denys@cs.yale.edu (Denys Duchier) Newsgroups: comp.emacs Subject: Re: Lisp Programming: Substring Searches, etc. Message-ID: <65906@yale-celray.yale.UUCP> Date: 10 Jul 89 00:16:19 GMT References: <397@lxn.eds.com> <65891@yale-celray.yale.UUCP> Sender: root@yale.UUCP Reply-To: Duchier-Denys@cs.yale.edu (Denys Duchier) Organization: Computer Science, Yale University, New Haven, CT 06520-2158 Lines: 20 In-reply-to: spencer@eecs.umich.edu (Spencer W. Thomas) In article , spencer@eecs (Spencer W. Thomas) writes: > In article <65891@yale-celray.yale.UUCP> Duchier-Denys@cs.yale.edu (Denys Duchier) writes: > (defun extract-file-extension (filename) > (and (string-match ".+\\.\\(.*\\)$" filename) > (substring filename (match-beginning 1) (match-end 1)))) > > Actually, probably better would be > (string-match ".+\\.\\([^.]*\\)$" filename) > This pattern will match the last ".", while the given pattern will > match the first one. > > -- > =Spencer (spencer@eecs.umich.edu) Wrong, .+ eats up as much of the string as possible. The version you propose can be simplified to "\\.\\([^.]*\\)$", but I rejected it when I wrote the proposed solution because I didn't want files like .login to be mistaken for files with an empty name and just an extension. --Denys