Greg was sharp to catch that you really want the link "label", rather than the href URL. But I would grab all of the elements with getElementsByTagName('A'). Then iterate through their firstChild nodes.
It's just as easy to pick up the 'nodeValue' of the 'firstChild', as it is to get the innerHTML or (innerText, which someone mentioned, which is less supported).
Here's a minimal example, looking for 'word1', 'word2', and 'word3'.
I will just add, that if you want to limit the links looked at for this to a subset of the links on the page or site, you could differentiate in other ways, by setting a particular className to the links you want to search. It would just complicate matters a bit to check the className of the links you grab. Herewith, a simple A Node iteration:
EXAMPLE:
<html>
<head>
<title>JavaScript match link label</title>
<script type="text/javascript">
var keywords = ['word1','word2','word3'];
function linklabels() {
var aels = document.getElementsByTagName && document.getElementsByTagName('A');
var aelsCt = aels.length;
var keywordsCt = keywords.length;
for (var i = 0; i < aels.length; i++) {
var v= aels[i].firstChild.nodeValue;
//this is the link label, the text seen as the link
for (var j=0; j < keywordsCt; j++) {
var re = new RegExp(keywords[j]);
if (re.test(v)) {
alert('refreshing to http://google.com/' + v);
//window.location.href = "http://google.com/" + v;
}
}
}
}
window.onload=linklabels;
</script>
</head>
<body>
<p><a href="#">word1</a> | <a href="#">word2</a> | <a href="#">word3</a>
<br /><a href="#">word1</a> | <a href="#">word2</a> | <a href="#">word3</a></p>
</body>
</html>