From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Harry Putnam Newsgroups: gmane.emacs.help Subject: Re: NON-trivial regular expression problem (could not find on google) Date: Sat, 18 Jan 2003 21:38:16 GMT Organization: Still searching... 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 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1042926044 30448 80.91.224.249 (18 Jan 2003 21:40:44 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 18 Jan 2003 21:40:44 +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 18a0hi-0007uf-00 for ; Sat, 18 Jan 2003 22:40:38 +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 18a0ia-0002Cj-04 for gnu-help-gnu-emacs@m.gmane.org; Sat, 18 Jan 2003 16:41:32 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!207.115.63.142!prodigy.com!prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr15.news.prodigy.com.POSTED!cbca52ab!not-for-mail Original-Newsgroups: comp.lang.lisp,comp.lang.awk,comp.unix.shell,gnu.emacs.help User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i686-pc-linux-gnu) Cancel-Lock: sha1:f0UimTW9IyNuXOVlYOhtCJfaxiU= Original-Lines: 49 Original-NNTP-Posting-Host: 63.207.142.38 Original-X-Complaints-To: abuse@prodigy.net Original-X-Trace: newssvr15.news.prodigy.com 1042925896 ST000 63.207.142.38 (Sat, 18 Jan 2003 16:38:16 EST) Original-NNTP-Posting-Date: Sat, 18 Jan 2003 16:38:16 EST X-UserInfo1: Q[R_PJON]ZWSCFD[LZKJOPHAWB\^PBQLGPQRZ_MHEQR@ETUCCNSKQFCY@TXDX_WHSVB]ZEJLSNY\^J[CUVSA_QLFC^RQHUPH[P[NRWCCMLSNPOD_ESALHUK@TDFUZHBLJ\XGKL^NXA\EVHSP[D_C^B_^JCX^W]CHBAX]POG@SSAZQ\LE[DCNMUPG_VSC@VJM Original-Xref: shelby.stanford.edu comp.lang.lisp:103181 comp.lang.awk:24425 comp.unix.shell:139865 gnu.emacs.help:109143 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:5669 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5669 democrat@india.com (Instant Democracy) writes: Let me say first, that I'm not sure I understand the problem but after several readings it appears to be simply that you want to reduce the file names to the last componenet only. > A frequent problem involves simplifying a pathname. The string format we > can expect to encounter is covered by the following three examples: Overlooking the `"' part for a moment, that problem is often handled with shell operators % # or %% ## rather than regex. > "dir.name/../dir/../file" > "dir/../d2/../file.ext" > "d1/d2/../../file.ext" In any of the bourn based shells. var='dir.name/../dir/../file' echo ${var##*/} file > 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". In the above scheme they can be handled like: var='"dir.name/../dir/../file"' echo ${var##*/}|sed 's/\"//' file > 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. Not sure I see why you would need to eleminate anything if ../.. is not present. > 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. Do the shell operators mentioned solve it? Or have I missed the boat entirely?