[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NON-trivial regular expression problem (could not find on google)
From: |
Edi Weitz |
Subject: |
Re: NON-trivial regular expression problem (could not find on google) |
Date: |
19 Jan 2003 00:03:10 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
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
<http://www.lispworks.com/reference/HyperSpec/Body/f_tn.htm>.
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.
- 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 <=
- 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, 2003/01/18
- 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