Replace specific links with the underlying linktext

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

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

Replace specific links with the underlying linktext

Postby gerd » Thu Jan 21, 2010 8:11 pm

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: 2162
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace specific links with the underlying linktext

Postby DataMystic Support » Mon Feb 01, 2010 3:43 pm

Hi Gerd,

Try this perl pattern for example.com:

Code: Select all

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


Replace with:

Code: Select all

$1
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

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

Re: Replace specific links with the underlying linktext

Postby gerd » Tue Feb 02, 2010 1:02 am

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: 2162
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace specific links with the underlying linktext

Postby DataMystic Support » Wed Feb 03, 2010 7:29 am

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>
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest