I have a function that tests a RegExp, but it returns true half the times, with the same values!
(I modified the code to show the problem, because in the project the function is fired everytimes the user digits something)
Where do I wrong?
intent.js file:
var intentTags = [
{
desc: 'elenca numeri telefonici',
type: 'numero',
phrases: ['numero', 'numeri'],
regex: new RegExp( /(?<!\w)(nu?m?e?r?[oi]?)\b/, 'gi' )
},
]
module.exports = {
attivati: function attivati(digitato) {
return intentTags[0].regex.test( digitato )
}
}
nodejs file:
var intent = require('./intent')
var val = "numeri"
var result1 = intent.attivati( val );
var result2 = intent.attivati( val );
var result3 = intent.attivati( val );
var result4 = intent.attivati( val );
var result5 = intent.attivati( val );
var result6 = intent.attivati( val );
console.log( val, "returns: ", result1, result2, result3, result4, result5, result6 );
espected result: numeri returns: true true true true true true
actual result: numeri returns: true false true false true false