Oh my bad, I totally misunderstood. This will get all text outside of < tags >. So, this isn't going to help you at all... sorry, lol
Main Topics
Browse All TopicsHi,
I have a javascript that highlights glossary terms on my page. Everything is working fine except in the case when the glossary term inside a link. ie: <a href="page.aspx">glossary term</a>
In this case I do not want "glossary term" to be touched. How can I accomplish this? Attached is the javascript I'm using.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is my code that I'm using in C#..:
Yeah, you can translate it to vb, it's easy. Here is a nice utility here to do that: http://www.codechanger.com
Basically the linkFinal parameter is the finalized text being passed in from the previous operation.. I work with it in here, continuing it's polishing before I display it to the user. myHits is an array of all the words that came back matching the criteria entered by the user...
Let me know if you have trouble understanding it.
I don't see a problem with your regex pattern, tested in JS:
<script type="text/javascript">
var re = /(glossary term)(?![^<]*>|[^<]*<\/a>)
var sourcestring = 'glossary term<a href="page.aspx">glossary term</a>glossary term<test glossary term test>glossary term';
var replacementpattern = '<a href="glossary.aspx#$1" title="def" class="glossary">$1</a>';
var result = sourcestring.replace(re, replacementpattern);
alert("result = " + result);
</script>
Do you need a test app within .NET?
Imports System.Text.RegularExpress
Module Module1
Sub Main()
Dim sourcestring as String = "glossary term<a href=""page.aspx"">glossar
Dim replacementstring as String = "<a href=""glossary.aspx#$1"" title=""def"" class=""glossary"">$1</a>"
Dim matchpattern as String = "(glossary term)(?![^<]*>|[^<]*</a>)"
Console.Writeline(re.Repla
End Sub
End Module
In my examples I hardcoded "glossary term" but you could easily do that with a string variable instead.
I might be missing something but if you want to test my version of your pattern:
http://www.myregextester.c
Business Accounts
Answer for Membership
by: GewgalaPosted on 2008-02-15 at 14:34:02ID: 20906639
This is what I use for C# to do the same thing... don't know if it will be the exact same for javascript... hope it helps or at least guides you in the right direction :)
?=.*<)\b
\b(?<=>[^<]*?)keywordHere(