better...
Main Topics
Browse All TopicsHi.
I need a regular expression for finding relatives paths e.g. ../img/xxx.gif or ./img/xxx.gif or img/xxx.gif in general ../path/to/file/xxx.gif
I am using python2.5.
Please provide a clear solution...I am not an expert in regex...
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
My bad...I was not clear....
I have a html page and there are relative tags in java scripts. I need to search the string and find patters that look like a relative url so I can do a find and replace.... I will be looking for files that have extensions if e.g. css,js,jpg etc....
So...if given this string "adadfadf adafd ../test/test.gif adfadfaf" how can I do this for any arbitrary pattern?
The answer HonorGod gave is quite good. It doesn't match the img/xxx.gif case you gave, but that's easily fixed.
The problem, however, isn't particularly well defined. For example, is "foo.gif" a relative path? Strictly speaking it is, but that may not be what you have in mind.
Are you looking for all paths that have at least one / (or \) and don't start at the root (don't begin with a /). What's your platform (Windows, Linux, ...)?
Again, using HG's script above, where it splits into strings first, you can use this:
r'(^[^\\/].*[\\/].*)'
which basically says: 1) don't start w/ a / or \, then there must be at least one / or \ somewhere else in the string.
cool...almost there...here a real example...
because of the path between the ' ' it did not find it.....
tt = """ <body onload="MM_preloadImages('
"""
Business Accounts
Answer for Membership
by: HonorGodPosted on 2009-05-22 at 18:14:58ID: 24456260
Something like this perhaps?
Select allOpen in new window