I have a Wiki program that works locally and organizes articles and adds HTML links that link to functions (to load subsequent articles).
Some code to wrap your head around:
for each (var keyword:String in thisArticleArray) {
var pattern:RegExp = new RegExp(keyword,'/gi');
contents = contents.replace(pattern,"<a href=\"event:" + "$&" + "\"><b>" + keyword + "</b></a>");
}
Anyways, the idea is that these links link to new articles. That isn’t so bad. But now, I have articles with names that contain other article names. Example would be “Apple” and “Apple Pie”. How would I differentiate between these? Right now it just screws up when it hits that area…
Any ideas?
Well, I would simply reverse-sort
thisArticleArrayby string length. This way the code will always attempt to match the longer matches before the shorter ones.