KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need to compare 2 strings as equal such as these: Lubeck == Lübeck In JavaScript. Why? Well, I have an auto-completion field that's going out to a Java service using Lucene, where place names are stored naturally (as Lübeck), but also indexed as normalized text, import sun.text.Normalizer; oDoc.setNameLC = Normalizer.normalize(oLocName, Normalizer.DECOMP, 0) .toLowerCase().replaceAll("[^\\p{ASCII}]",""); This way some-one who doesn't know to type "Mèxico" can type "mexico" and get a match which returns "Mèxico" (among a lot of other possible hits, like "Café Mèxico, Dubai, UAE"). Now the thing is I don't have the ability to change the service to do any highlighting on the server side, therefore I am highlighting on the client JavaScript side with something like: return result.replace( input.replace(/[aeiou]/g,"."), "<b>$1</b>"); It's a little more fancy because I am escaping special regex characters in the input. This is fine for simple one word matches at the beginning of a hit, but it really breaks down if you suddenly wish to support multi-word matches like "london cafe": input = input.strip().toLowerCase(); //fyi prototype's strip is like trim re = new RegEx(input.replace(/[aeiou]/g,".").replace(/\s+/g,"|"),"gi"); return result.replace(re, "<b>$1</b>"); This doesn't work for say "london ca" (was typing london cafe), because it would mark "Jack London Cabin, Dawson City, Canada" as: "Ja<b>ck</b> <b>London</b> <b>ca</b>bin, Dawson <b>Ci</b>ty, <b>Ca<b/>nada" [note the "ck" and "Ci" particularly] Therefore I'm sort of looking for something that's not as crazy as: input = input.strip().toLowerCase(); input = input.replace(/a/g,"[ÀàÁáÂâÃãÄäÅ寿ĀāĂ㥹]"); input = input.replace(/e
Tags (comma-separated)
Save Edits
Cancel