Thank you both for your answers!

I was already considering using Eric's idea of stripping the accents
and comparing the words. Since this would apply to highlighting (too
many h's and g's in this word!) a typed word in a sentece, I think I
would have to do something like that:

Let's suppose I have a list of names I want to autocomplete from and
"Maria José da Silva" is one of them. When the user types "Jose", the
database (MySQL using utf-8) searches for it accents-insensitivily and
retrieves the name correctly. But the highlighting doesn't word in
that case!

I took a look in the code and it's a big RegEx that does the job.
Since I'm not very familiar with RegEx's (not for long because I just
bought a book about the subject :) ) I thought about stripping the
accents and comparing, but this wouldn't help me because the current
RegEx REPLACES the typed string with the highlighted one, so I would
end with "Maria <strong>Jose</strong> da Silva". So my ideia is to
this:

function highlight(sentence, typed_word)
{
    var type_word_no_accents = stripAccents(typed_word);
    var sentence_no_accents = stripAccents(sentence);
    var position = findTypedWordIndex(sentence_no_accents,
type_word_no_accents); // Here I'd use the current RegEx
    var length = getLength(typed_word);

    return hightlightWord(sentence, position, length);
}

I'm not worried with syntax right now, that I can learn on my own.

So do you guys think that's a good approach? I think it could work...

Reply via email to