help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NON-trivial regular expression problem (could not find on google)


From: Kai Großjohann
Subject: Re: NON-trivial regular expression problem (could not find on google)
Date: Sat, 18 Jan 2003 22:46:58 +0100
User-agent: Gnus/5.090013 (Oort Gnus v0.13) Emacs/21.3.50 (i686-pc-linux-gnu)

democrat@india.com (Instant Democracy) writes:

> 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.

Let s be a string such as the above, but without quotes.  Then

    (expand-file-name s "/")

will return a suitable string, except that it starts with slash.

So in Emacs Lisp, you can do it without regular expressions, but in
three steps:

    (1) Remove quotes
    (2) Above Lisp expression
    (3) Remove leading slash

In Emacs, regular expressions are often not the answer.
-- 
Ambibibentists unite!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]