ExtJS Javascript Library for Beginners!

The Ext Javascript library for beginners, as I learn ExtJS so will you!

Posts Tagged ‘link matching

Matching Backlinks and Anchor Text with a Regular Expression

with one comment

Hi Guys,

If anyone reads this, well done you. You’re about to become witness to my first ever published regular expression, so go easy on the critique!

I needed this to show what pages were linking into other pages (backlinks) and what was the associated anchor text used by the link. I spent a morning or so playing around with the following regular expression to try and match all backlinks to a specific URL and its anchor text.


<a [^/>]*href=["\'](your-url-here).*["\'][^/>]*/?>(.*)

This does the job very nicely, I’m sure it could be speeded up slightly to avoid being overtly greedy. But for now I’m happy with it.

Notes

  1. You must quote the URL you use. There is a way in ExtJS to do this and PHP.
  2. Ext.escapeRe() and preg_quote() in PHP should get the job done!

Written by jameshd

6th October, 2008 at 9:48 pm

Posted in PHP

Tagged with , , ,

Follow

Get every new post delivered to your Inbox.