Page 1 of 1

Absolute Links on Same Line Regex Needed

Posted: Sat Apr 07, 2007 6:33 pm
by sharingsunshine
Hello,

I am needing a regex that will stop at the end of the href tag and if two hrefs are on the same line it will pick up both.

I went to the regex library and tried this pattern that I got from the library(<(?:.*?)\s)href\s*=([\s"'])*/?([^\2:#]+?)\2((?:.*?)>)

against the following lines of html, note the lines are broken for purposes of the forum only

<b>Joints</b>: <b><a href="/Rosemary_100_Pure_Essential_Oil_p_53.html">Rosemary</a></b>, <A href="/Peppermint_100_Pure_

Essential_Oil_p_47.html"><b>Peppermint</b></a>, <b><a href="/Cinnamon_Leaf_100_Pure_Essential_Oil_p_14.html">Cinnamon


</a></b>, <A href="/Peppermint_100_Pure_Essential_Oil_p_47.html"> This is what it caught.

**********************

Marjoram</a></b> and <b><a href="/Rosemary_100_Pure_Essential_Oil_p_53.html">Rosemary</a></b></p>

</a></b> and <b><a href="/Rosemary_100_Pure_Essential_Oil_p_53.html"> This is what it caught.



***********************

<A href="/Peppermint_100_Pure_Essential_Oil_p_47.html"><b>Peppermint</b></a>, <b><a href="/Cinnamon_Leaf_100_Pure_

Essential_Oil_p_14.html">Cinnamon


<A href="/Peppermint_100_Pure_Essential_Oil_p_47.html"> This is what it caught. You can see it caught the first link and missed the second.

Many of my html pages have multiple links on the same line

All I am trying to do is take the a href tags contents and insert http://www.domain.com/ or http://www.domain.com with or

without the slash depending upon if the contents have the slash or not. I can make two passes on it if there is a slash or not, if that is easier.

I am new to regex and I would appreciate if you could help me get clear on why it is catching more content than I need and/or leaving an entire

link out that is on the same line

Thanks,

Randal

Posted: Sat Apr 07, 2007 8:39 pm
by feyd

Posted: Sat Apr 07, 2007 10:42 pm
by sharingsunshine
Hello,

Thanks for the response. However I am not familiar with preg_match_all(). Even though I looked at the manual I wasn't able to grasp how to use that command, in my situation.

I am using a Mac with Dreamweaver 2004 and wanting to change the links on my desktop and then upload them. I didn't mention this before because I thought saying they were html links was enough. I can see now that I should have mentioned that so please forgive me.

If this can be used on a desktop level please explain further. If not, then please someone give me advice on the regex I need.

Thanks,


Randal