Thanks Niki
Unfortunately I cant search for http:// or www because the search
value could be in the querystring or in the page name. I've been
trying to look for href= and then find the closing >
I'll have a fiddle with your suggestion.
Thanks again
> I think you need a negative lookbehind, something like:
>
[quoted text clipped - 38 lines]
> >
> > Sam
Samuel Hon - 13 May 2004 16:40 GMT
I have a slightly different approach now which is going wrong because
the MatchCollection has 8 values (correct) which are blank (incorrect)
Can anyone see what i'm blatantly missing?
Ta in advance
Dim strText As String = "This is my long string with a <a
href=""http://localhost/test.aspx"">Test Link using quotes</a>,<BR>a
<a href = 'http://localhost/test.aspx'>Test Link using apostrophes</a>
<BR> and one with a <A
HREF=""http://localhost/test.aspx?test"">querystring</a>."
public Function Highlight(strText As String)
Dim objRegEx As New RegEx("<[^<>]*>", RegexOptions.IgnoreCase)
'Find All tags and place in collection
Dim colM As MatchCollection = objRegEx.Matches(strText)
'Replace all tags with $!$
Dim strReplaced As String = objRegEx.Replace(strText,"$!$")
'Create new objRegEx looking for test
objRegEx = New RegEx("(test)", RegexOptions.IgnoreCase)
'Replace All with highlight
strText = objRegEx.Replace(strReplaced, _
"<span style='background-color:#FFFF66;'>$1</span>")
'Loop through all items in the collection replacing $!$
For i As Integer = 0 to colM.Count -1
Dim m As Match = colM.Item(i)
strText = strText.Replace("$!$",m.ToString()) & vbcrlf
Next i
'Return
Return strText
End Function
Samuel Hon - 13 May 2004 16:51 GMT
Ignore my last message, I was being stupid and forgot what Replace does