[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NON-trivial regular expression problem (could not find on google)
From: |
William Park |
Subject: |
Re: NON-trivial regular expression problem (could not find on google) |
Date: |
19 Jan 2003 01:05:52 GMT |
User-agent: |
tin/1.5.11-20020130 ("Toxicity") (UNIX) (Linux/2.4.20 (i686)) |
In comp.unix.shell Instant Democracy <democrat@india.com> 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, <opengeometry@yahoo.ca>
Linux solution for data management and processing.
- NON-trivial regular expression problem (could not find on google), Instant Democracy, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google), Harry Putnam, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google), Kai Großjohann, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google), AW, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google), Edi Weitz, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google), Larry Clapp, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google), Dr. Yuan Liu, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google), John W. Krahn, 2003/01/18
- Re: NON-trivial regular expression problem (could not find on google),
William Park <=
- Re: NON-trivial regular expression problem (could not find on google), Peter J. Acklam, 2003/01/19
- Re: NON-trivial regular expression problem (could not find on google), Bruce Barnett, 2003/01/24