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: Harry Putnam
Subject: Re: NON-trivial regular expression problem (could not find on google)
Date: Sat, 18 Jan 2003 21:38:16 GMT
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i686-pc-linux-gnu)

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?


reply via email to

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