1
我使用免費的Javascript來搜索和突出顯示網站上的文本。 如果search-stirng是單詞的一部分,則應該突出顯示空洞單詞。 示例:搜索「over」,而不是「stackoverflow」必須突出顯示。Javascript:搜索和splitText與變異元音,元音變音,
所以第一步是搜索使用正則表達式來選擇整個單詞的開頭文字,並返回開始位置:
var string='over'; //String to search
var pattern= new RegExp("[a-zA-Záéíóäëiöúàèììùüß-]*"+string,'i');
var position = node.data.toUpperCase().search(pattern);
接下來是調用的亮點功能....
if (position >= 0)
return highlight(node, position, string);
else
return 0;
...其使用的起始位置和檢測字的最後一個字符(endbit)
function highlight(node, position, string){
var middlebit = node.splitText(position);
var endbit = middlebit.splitText(middlebit.data.search(/[^a-zA-Záéíóäëiöúàèììùüß-]/));
[...] next: highlight the word...
這就好,只要你不使用變異元音,元音變音等等。 例如:如果您搜索結束,整個單詞「stackoverflow」突出顯示。 如果你搜索「würstchen」(例如在bratwürstchen)它不起作用。 它lookes等,它們
var position = node.data.toUpperCase().search(pattern);
或
var middlebit = node.splitText(position);
不具有那種特殊字符的工作。
希望有人有一個想法如何解決這個問題。
太感謝你了,
Bndr
沒有? http://stackoverflow.com/search?q=regex+OR+regexp+umlaut – mplungjan 2011-03-07 10:53:36