Reply to Re: Regexp - matching text not containing certain count of certain characters

Your name:

Reply:


Posted by Jiri Fogl on 10/20/54 11:44

Thanks for advice, but this is not exactly what I need. I'll try to
explain it better:

Regular expression I need has to search through path or URL and find
every reference to a parent directory, including this parent directory.

For example if I have URL like this:
http://www.example.com/mydir/../myotherdir
RE is supposed to match /mydir/../ so I can replace it by a single slash
and get "definite" URL.

I have built a regexp to achieve this:
ereg_replace('/[^/]+/\.\./', '/', $url);

Problem of this RE appears in case of URL like this:
http://www.example.com/level1/level2/level3/level4/../../../../target

This URL is pointing to http://www.example.com/target, but ereg_replace
above will give me
http://www.example.com/level1/level2/level3/../target. After looped
ereg_replace I get URL http://www.example.com/level1/level2/target which
is wrong.

I need to modify this part of RE: /[^/]+/
Now it says "match any string if it doesn't contain a slash" and I need
it to say "match any string if it doesn't contain a slash and it is not
..." and I need it to be a part of a RE above.



John Dunlop wrote:
> Jiri Fogl:
>
>> I'm trying to build a regular expression (POSIX extended). One part of
>> it has to match any text not containing a slash except standalone two
>> dots (..), but I can't find the way to say something like "match any
>> count of any characters except string ..".
>>
>> For example, it should match
>> ..anything..
>> aaa..
>> ...
>>
>> but must not match
>> anything/containing/a/slash
>> ..
>
> (UNTESTED)
>
> !ereg('^\.\.$|/',$subject)
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация