Reputation: 91
I am going to highlight search result in page better using c# or JavaScript. Problem is that search text and result is in Chinese which have no space between characters. example of this problem is:
var A = abrfct;
var B= abefhwefoba;
so I want to highlight all characters in B which contain any character in A. in this example : `
I want to highlight: ab, f, b, a in B.
Upvotes: 0
Views: 161
Reputation: 198496
Use XRegExp library, then you can use things like:
var definition = "漢語,又称中文(單指文字)、汉文、华文,其他名稱有唐文、中國語,唐話、中國話等[1],是属汉藏语系的分析语,具有声调";
var language_but_especially_han = "[汉文]+"
XRegExp.replace(definition, language_but_especially_han, "<span class='highlight'>$1</span>");
results in
漢語,又称中[文](單指[文]字)、[汉文]、华[文],其他名稱有唐[文]、中國語,唐話、中國話等[1],是属[汉]藏语系的分析语,具有声调
(i.e. 6 matches, of which 4 are 文, one is 汉, and one is 汉文)
Also, posting a real problem instead of a replacement problem will probably get you a better, or faster solution.
Upvotes: 1