Jump to content
Ketarin forum

Capturing relative path with regex.


Etz
 Share

Recommended Posts

For example webpage contains lots of content in different iframes:

 

"><iframe name="ifrm5" src="../../blah/page_xy.htm" width="345" height="130" vspace="0" hspace="0" marginwidth="0" marginheight="0" frameborder="1"></iframe>

 

How to capture that "blah/page_xy.htm" from there with regex?

Considering that I want to identify that by "page_xy" part of url, tried for hours myself and didnt seem to succeed...

 

Basically I came to this:

 

<iframe [^>]*(src="[^"]+")[^>]*

 

Only problem is that it matches URL in first iframe it finds on page, but I need to match a certain one containing certain link, identified by "page_xy.htm" part, in URL.

 

EDIT : Nevermind, found solution already:

 

<iframe [^>]*(src="[^"]+page_xy[^"']+")[^>]*

 

Still have to find out, how to strip ../../ part from that match...

 

Quick and dirty solution:

 

<iframe [^>]*src="../../([^"]+page_xy[^"']+)[^>]*

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.