add target equals blank to links without any target
Posted: Tue Oct 28, 2008 8:40 pm
I found this online:
('/<a[^>]*?href=[\'"](.*?)[\'"][^>]*?>(.*?)<\/a>/si','<a href="$1" target="_blank">$2</a>',$s);
first, i'd just like to see that example for textpad, without the exclusions below so it is easier for me to follow.
But really this is what I need:
I need to open an html document, and add a space and target="_blank" to the end of the anchor in all cases except when within that opening anchor there is already the word 'target' and, if possible, in all cases except when there is not a match for 'searchengine' anywhere within that anchor (ie i need to ignore http://www.searchengine-resources.com and NOT add target to it since that would be the domain name of the site).
Yes, sometimes the anchor is on two different lines. I imagine this may cause some issues, but even if i could partially accomplish this task it would make my life easier.
thanks for any help.
I truly have no idea how you all can understand these regular expressions.
If it is super simple I can find a simple pattern, but when it comes to quotes, slashes, variable character types, and especially backreferencing, I am lost.
do appreciate any time anybody can provide for even a partial soluton.
steven
('/<a[^>]*?href=[\'"](.*?)[\'"][^>]*?>(.*?)<\/a>/si','<a href="$1" target="_blank">$2</a>',$s);
first, i'd just like to see that example for textpad, without the exclusions below so it is easier for me to follow.
But really this is what I need:
I need to open an html document, and add a space and target="_blank" to the end of the anchor in all cases except when within that opening anchor there is already the word 'target' and, if possible, in all cases except when there is not a match for 'searchengine' anywhere within that anchor (ie i need to ignore http://www.searchengine-resources.com and NOT add target to it since that would be the domain name of the site).
Yes, sometimes the anchor is on two different lines. I imagine this may cause some issues, but even if i could partially accomplish this task it would make my life easier.
thanks for any help.
I truly have no idea how you all can understand these regular expressions.
If it is super simple I can find a simple pattern, but when it comes to quotes, slashes, variable character types, and especially backreferencing, I am lost.
do appreciate any time anybody can provide for even a partial soluton.
steven