JSFiddle - React, Tailwind, and code Playground
HTML
<div id="result"></div>
JavaScript
var title = "this is simple string with finnish word tämä on ääkköstesti älkää ihmetelkö";
// Does not work
var searchterm = "äl";
// does not work
//var searchterm = "ää";
// Works
//var searchterm = "wi";
//alert(asciiOnly(title));
//alert(asciiOnly(searchterm));
if ( new RegExp("\\b"+asciiOnly(searchterm), "gi").test(asciiOnly(title)) ) {
$("#result").html("Match: ("+searchterm+"): "+title);
} else {
$("#result").html("nothing found with term: "+searchterm);
}
function asciiOnly(input) {
var output = "";
for (var i = 0; i < input.length; i++) {
if (input.charCodeAt(i) < 128) {
output += input.charAt(i);
}
else {
percents = encodeURI(input.charAt(i));
percents = 'QQ' + percents;
output += percents.replace(/%/g, "");
}
}
return output;
}