diff --git a/database/RandomSentence.js b/database/RandomSentence.js index 5ef7d4c4953ef05c5558bdf578d817e4a5a0c40c..0fb2b498de6d2b4d01c5172e020e5d3d8d97ad71 100644 --- a/database/RandomSentence.js +++ b/database/RandomSentence.js @@ -11,6 +11,7 @@ const actionRE = new RegExp('<action>', 'gi'); const MAX_ITERATIONS = 10; function fillAllRandomObject(sentence, regularExpr, category){ + const matches = sentence.matchAll(regularExpr); let objectString = ""; let newSentence = sentence; @@ -23,12 +24,11 @@ function fillAllRandomObject(sentence, regularExpr, category){ } function shouldBeFilled(sentence) { + return [actorRE, reasonRE, sourceRE, actionRE].some((re) =>{ - const b = re.test(sentence) - if(b){ - const matches = sentence.matchAll(re); - for(let match of matches) console.log(match); - } + const result = re.test(sentence) + re.lastIndex = 0; + return result; }); }