From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Dr. Yuan Liu" Newsgroups: gmane.emacs.help Subject: Re: NON-trivial regular expression problem (could not find on google) Date: Sun, 19 Jan 2003 00:36:12 GMT Organization: http://www.stemnet.nf.ca/~yliu/sciences.html#physics Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <3E29F452.6070006@stemnet.nf.ca.remove_this> References: <7606630f.0301181219.60384da2@posting.google.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1042936786 26067 80.91.224.249 (19 Jan 2003 00:39:46 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 19 Jan 2003 00:39:46 +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 18a3V2-0006m3-00 for ; Sun, 19 Jan 2003 01:39:44 +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 18a3Vb-0007Tb-05 for gnu-help-gnu-emacs@m.gmane.org; Sat, 18 Jan 2003 19:40:19 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!wn11feed!wn14feed!wn13feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi.com!sccrnsc03.POSTED!not-for-mail User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en Original-Newsgroups: comp.lang.lisp,comp.lang.awk,comp.unix.shell,gnu.emacs.help Original-Lines: 41 Original-NNTP-Posting-Host: 12.234.28.162 Original-X-Complaints-To: abuse@attbi.com Original-X-Trace: sccrnsc03 1042936572 12.234.28.162 (Sun, 19 Jan 2003 00:36:12 GMT) Original-NNTP-Posting-Date: Sun, 19 Jan 2003 00:36:12 GMT Original-Xref: shelby.stanford.edu comp.lang.lisp:103189 comp.lang.awk:24433 comp.unix.shell:139874 gnu.emacs.help:109161 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:5685 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5685 Instant Democracy wrote: > 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. > > For lines which do not have ../.. in them, this is > trivial, for example by regexp in sed, emacs etc. It turns out to be trivial in both cases. > The real problem is constructing a regular expression for the DIRNAME before the /.. In order to illustrate your question, I reconstructed test data to be non-trivial. The solution is just one regexp with one loop in sed, ':2dots; s;[^/]*/\.\./;;g; t2dots': $ sed ':2dots; s;[^/]*/\.\./;;g; t2dots' <