Replace specific links with the underlying linktext

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Replace specific links with the underlying linktext

Post by gerd »

Hi,
My target is to replace specific links (i.e. links to a specific domain with http ://www. or just http ://) or in other words links identified by a string. The replacement should be the linktext. I assume that this is quite a common filter but I could not find anything in the forum or in the filter list. The following Findings could not help me any further:
1. On Mon Dec 14, 2009 Simon wrote in a thread:
Why don't you just use Filters\Remove\HTML and XML\Remove all tags ?
2. Filter list: replace Hyperlink Target URL.fll and extract all external links.fll

This is my example text in which I want to replace all links to the domain example.com with the linktext but all other links should remain unchanged. So a link like <a class="css" title="here comes description" target="_blank" href="http://www.example.com/example.html">Text and so on</a> should become "Text and so on" or <a href="http://example.com/moreexamples.php">moretext</a> should now be converted to "moretext" whereas a link to all other domains should remain untouched.

I did some trial and error with
Perl Pattern
<a[^>]*>.*</a>
Send matching text to subfilter

but I am not good enough for it. Since I feel that this is a filter of general interest it might be good to get professional advice from Simon.
Thanks Simon
gerd
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace specific links with the underlying linktext

Post by DataMystic Support »

Hi Gerd,

Try this perl pattern for example.com:

Code: Select all

<a[^>]*href="[^>]*.example\.com[^>"]*"[^>]*>(.*)</a>
Replace with:

Code: Select all

$1
gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Re: Replace specific links with the underlying linktext

Post by gerd »

Simon,
you are great. It works exactly as requested. I understand about 90-95% of your above Perl Pattern Code. I also tried to find the perl pattern code with EasyPattern Helper but it was just too "big" for me. This is one more example which helps a lot to understand the use of Textpipe much better.
Thanks again
gerd
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace specific links with the underlying linktext

Post by DataMystic Support »

No worries Gerd,

With EasyPatterns, the search would have been:

Code: Select all

<a[ 0+ not '>' ]href="[ 0+ not '>' ].example.com[ 0+ not '>"' ]"[ 0+ not '>' ]>[ capture( 0+ chars ) ]</a>
Post Reply