It's been a while since I last wrote JavaScript, so any mistakes are probably very obvious.
I'm currently facing an issue with using RegExp.match(..) in JavaScript. It seems to be skipping the first character in the strings that are being searched for. Here is the output from a list of strings:
*query = 'g'*
Genetic engineering: g,g
Gene therapy: null
Surfactant: null
Human cloning: g
Protein production: null
Microfluidics: null
Polymerase chain reaction: null
RNA: null
Restriction enzyme: null
Picotechnology: g
Femtotechnology: g
Grey goo: g
Molecular engineering: g,g
Microfluidics: null
Molecular nanotechnology: g
Nanoengineering: g,g
Atom probe: null
Maxwell's demon: null
For example, 'Genetic engineering' should match as: g,g,g but the first (and only the first) character is missing. If I type 'enetic', 'genetic engineering' will successfully match.
Here is the code snippet causing the issue:
function createFilterFor(query) {
return function filterFn(state) {
let re = new RegExp(query, 'g');
console.log(state+":\t"+state.match(re,'ig'))
return (state.match(re,'ig') != null? true : false );
};
}
This function is designed to provide a list of items for a search text field. Here are some of the results:
(8) ["Genetic engineering", "Human cloning", "Picotechnology", "Femtotechnology", "Grey goo", "Molecular engineering", "Molecular nanotechnology", "Nanoengineering"]