Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions

Status
Not open for further replies.

vpekulas

Programmer
Jan 8, 2002
154
CA
I'm using this function to phrase the text (strDES) for occurrences of words (arrKEYS) and I highlight them using the RegEx.

The problem I have is that it highlight text that is between the HTML tags it created, more specifically the
<span class='spanMATCH'>$1</span>
Is there any way to tell the RegEx to keep highlighting, only text out of the <> tags ?


Code:
PRIVATE FUNCTION HIGHLIGHT(strDES, arrKEYS)
   Dim regEx, I
   Set regEx = New RegExp
   FOR I = 0 to Ubound(arrKEYS)            
       regEx.Global = True
       regEx.IgnoreCase = True
       'regEx.Pattern = "(\b" & arrKEYS(I) & "[?!, ])" ' REGEX FOR WHOLE WORDS ONLY
       regEx.Pattern = "(" & arrKEYS(I) & ")" ' Any occurance of the match
       strDES = regEx.Replace(strDES,"<span class='spanMATCH'>$1</span>")
   NEXT
   Set regEx = Nothing    
   HIGHLIGHT = strDES
END FUNCTION

&quot;Taxes are the fees we pay for civilized society&quot; G.W.
 
the most effective work around I ahve always used in this type of situation, is to remove any HTML tags in the values you pass the function.

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
Well I can not do that simply becasue the very function that phrases the text adds <span> tag to the text (strDES)
and it's repeated with X times, depending how many keywords I want highlighted.

&quot;Taxes are the fees we pay for civilized society&quot; G.W.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top