I dont know enough to modify following code that will show me the word starting with the inputted characters.For eg.: If I type E or e it shows me "Electrical,Electronics,Mechanical" but I want only "Electrical,Electronics" to be displayed.How to do this?
I am using jquery autoplete plugin.
source: function(request, response) {
var matcher = new RegExp($.ui.autoplete.escapeRegex(request.term), "i");
response(select.children("option").map(function() {
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text)))
return {
label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autoplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>"),
value: text,
option: this
};
}));
I dont know enough to modify following code that will show me the word starting with the inputted characters.For eg.: If I type E or e it shows me "Electrical,Electronics,Mechanical" but I want only "Electrical,Electronics" to be displayed.How to do this?
I am using jquery autoplete plugin.
source: function(request, response) {
var matcher = new RegExp($.ui.autoplete.escapeRegex(request.term), "i");
response(select.children("option").map(function() {
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text)))
return {
label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autoplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>"),
value: text,
option: this
};
}));
Share
Improve this question
edited Dec 4, 2013 at 12:39
falsarella
12.4k10 gold badges74 silver badges118 bronze badges
asked Dec 15, 2011 at 12:44
SaurabhSaurabh
1571 gold badge3 silver badges12 bronze badges
0
1 Answer
Reset to default 10In Javascript RegExp, ^
means startsWith
:
var matcher = new RegExp("^" + $.ui.autoplete.escapeRegex(request.term), "i");