I'm upgrading some code written in visual basic. The regex doesn't work as I'd expected.
Basically the regex is applied in a loop, it replaces keywords with anchor links. So it builds up a string which could have lots of phrases / words replaced with links to those phrases / words.
The problem is that if I have two phrases wiki and wikipedia. It will do wikipedia first as I've开发者_StackOverflow中文版 ordered the query to produce the list of phrases by length. However, the regex will replace wikiepedia then wiki reglardless of the whether wikipedia is converted to a link.
So I get a link within a link.
Heres the code.
do
oRegExp.Pattern = "(" & title & ")(?![^<]*>|[^<]*</a>)"
title = " <a href=""view.asp?id=" guid & """>" & "$&" & "</a> "
content = oRegExp.Replace(content, title)
loop
Adding part of my comment as answer as it seems to have solved it for you.
You can try adding surrounding \b
around your title, like "(\b" & title & "\b)
.
When doing this you do not need to do the replacement in any specific order, as long as you are replacing singe words.
精彩评论