| 
	
 | 
 Posted by Jiri Fogl on 06/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] 
 |