From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Edi Weitz Newsgroups: gmane.emacs.help Subject: Re: NON-trivial regular expression problem (could not find on google) Date: 19 Jan 2003 00:03:10 +0100 Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87hec6oyc1.fsf@bird.agharta.de> References: <7606630f.0301181219.60384da2@posting.google.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1042931148 12429 80.91.224.249 (18 Jan 2003 23:05:48 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 18 Jan 2003 23:05:48 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18a227-0003EL-00 for ; Sun, 19 Jan 2003 00:05:47 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18a21u-0001Jr-08 for gnu-help-gnu-emacs@m.gmane.org; Sat, 18 Jan 2003 18:05:34 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!trane.agharta.DE!not-for-mail Original-Newsgroups: comp.lang.lisp,comp.lang.awk,comp.unix.shell,gnu.emacs.help Original-Lines: 40 Original-NNTP-Posting-Host: trane.agharta.de (62.159.208.82) Original-X-Trace: fu-berlin.de 1042930993 25431918 62.159.208.82 (16 [15706]) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-Xref: shelby.stanford.edu comp.lang.lisp:103185 comp.lang.awk:24430 comp.unix.shell:139870 gnu.emacs.help:109158 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:5683 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5683 democrat@india.com (Instant Democracy) writes: > Regular expression facilities are slightly varied in > sed > awk > lisp > emacs-lisp > Therefore these newsgroups can all contribute to the discussion. > > A frequent problem involves simplifying a pathname. The string format we > can expect to encounter is covered by the following three examples: > > "dir.name/../dir/../file" > "dir/../d2/../file.ext" > "d1/d2/../../file.ext" > > The "" are part of the string, and not just string delimiters. These > strings are inside regular text on the line. The paths are never > absolute so that you will not encounter "/d1/file.ext". > > The task is to eliminate patterns such as > DIRNAME/../ > from the path because they are redundant. In Lisp on a Unix system you would use the function TRUENAME provided that the file in question exists, see . If I understand your problem description correctly this can't be solved with regular expressions. Or, to be more exact, if the nesting of "../" parts can be arbitrarily deep you won't be able to solve your problem with a _single_ application of _one_ regular expression. However, it should be easy to do this with _repeated_ applications of a regular expression unless I missed something: perl -le 'while (<>) { 1 while s#[^/]+/\.\./##; print }' Edi.