From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: William Park Newsgroups: gmane.emacs.help Subject: Re: NON-trivial regular expression problem (could not find on google) Date: 19 Jan 2003 01:05:52 GMT Organization: Open Geometry Consulting Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <7606630f.0301181219.60384da2@posting.google.com> NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1042938693 30737 80.91.224.249 (19 Jan 2003 01:11:33 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 19 Jan 2003 01:11:33 +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 18a3zn-0007zc-00 for ; Sun, 19 Jan 2003 02:11:31 +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 18a3ys-0003PY-09 for gnu-help-gnu-emacs@m.gmane.org; Sat, 18 Jan 2003 20:10:34 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!static-3m-b2-6.highspeed.eol.CA!not-for-mail Original-Newsgroups: comp.lang.lisp,comp.lang.awk,comp.unix.shell,gnu.emacs.help Original-Lines: 42 Original-NNTP-Posting-Host: static-3m-b2-6.highspeed.eol.ca (64.56.232.6) Original-X-Trace: fu-berlin.de 1042938352 25240594 64.56.232.6 (16 [99293]) X-Orig-Path: not-for-mail User-Agent: tin/1.5.11-20020130 ("Toxicity") (UNIX) (Linux/2.4.20 (i686)) Original-Xref: shelby.stanford.edu comp.lang.lisp:103191 comp.lang.awk:24435 comp.unix.shell:139878 gnu.emacs.help:109163 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:5687 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5687 In comp.unix.shell Instant Democracy wrote: > "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. > > For lines which do not have ../.. in them, this is > trivial, for example by regexp in sed, emacs etc. > > The real problem is constructing a regular expression for > the DIRNAME before the /.. > > This DIRNAME can be described as a string that contains neither > / not double-dot but anything else. Perhaps I am overlooking > something else about DIRNAME. > > The regular expression for the first two cases is demonstrated by this > sed script although the lisp variants are identical. > > sed 's,\(^.*\)\(/\|"\)\([^/][^/]*/\.\./\)\(.*"\),\1\2\4,' > > The regex I use for DIRNAME is [^/]+ written above using * because > sed is without plus. What's wrong with that? ie. sed 's,[^/]\+/\.\./,,g' > > I will follow all the cross-posted newsgroups. If you prefer, because > some people are allergic to any cross-posting, you can post your reply > in just one of the groups pertaining to your application, ie lisp/elisp/sed/awk. -- William Park, Open Geometry Consulting, Linux solution for data management and processing.