[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NON-trivial regular expression problem (could not find on google)
From: |
John W. Krahn |
Subject: |
Re: NON-trivial regular expression problem (could not find on google) |
Date: |
Sun, 19 Jan 2003 00:53:45 GMT |
Instant Democracy wrote:
>
> 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.
$ perl -le'
@paths = qw( "dir.name/../dir/../file"
"dir/../d2/../file.ext"
"d1/d2/../../file.ext"
"../../../file"
);
for ( @paths ) {
print;
s%([^"]+)% local $_ = $1; 1 while s|[^/]+(?<!\.\.)/\.\./||g; $_ %e;
print;
}
'
"dir.name/../dir/../file"
"file"
"dir/../d2/../file.ext"
"file.ext"
"d1/d2/../../file.ext"
"file.ext"
"../../../file"
"../../../file"
John
--
use Perl;
program
fulfillment
- 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 <=
- 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