Jquery-textcomplete does not work with Unicode characters and missing space

1. I am trying to use jquery-textcomplete with an array of Unicode strings. When I type an English word, it works correctly, but Unicode words are not suggested. I think the problem is with the "term". Check out the code below and please help me out:

var words = ['සහන', 'වනක', 'google', 'suresh namal',  'facebook', 'github', 'microsoft', 'yahoo', 'stackoverflow'];

$('textarea').textcomplete([{
    match: /(^|\s)(\w{2,})$/,
    search: function (term, callback) {
        callback($.map(words, function (word) {
            return word.indexOf(term) === 0 ? word : null;
        }));
    },
    replace: function (word) {
        return word + ' ';
    }
}]);

Js feed

2. There is also a problem with the return key. When I type google after stackoverflow, it looks like stackoverflowgoogle. There is no space between "stackoverflow" and "google". How can i solve this? Thank.

+3
source share
1 answer
  • match, (\w)

    \w - , . [A-Za-z0-9 _].

    Unicode RegExp, : \u0000-\u007f


  1. - \s ( "s" ) RegExp, "", :

    \s , (...)

    \s (capital "S" ), , , * (), 0 .


, , RegExp, :

$('textarea').textcomplete([{
    match: /(^|\S*)([^\u0000-\u007f]{2,}|\w{2,})$/,
    search: function (term, callback) {
        callback($.map(words, function (word) {
            return word.indexOf(term) > -1 ? word : null;
        }));
    },
    replace: function (word) {
        return word+' ';
    }
}]);

JSFiddle

+1

Source: https://habr.com/ru/post/1691578/


All Articles