I am trying to update a project that detects a value such as ts-english, ts-german, ts-italian using regular expression. this code produces
var str = "ts-english";
let patt = /(?<=ts\-)\S+/i;
var res = patt.exec(str);
console.log (res)
output: [ 'english', index: 3, input: 'ts-english', groups: undefined ]
I want to be able to do the some thing for ts-1-english in a for loop. I understand I am supposed to use RegEx to set the variable during each iteration of the loop.
var str = "ts-1-english";
for (q=1; q <= 3; q++){
var mpatt = new RegExp ("/(?<=ts\\-" + q + "\\-)\\S+/i")
console.log (mpatt)
var res = mpatt.exec(str);
console.log ("q: " + (q) + " result of test: " + res)
}
this is my output.
//(?<=ts-1-)\S+/i/ q: 1 result of test: null
//(?<=ts-2-)\S+/i/ q: 2 result of test: null
//(?<=ts-3-)\S+/i/ q: 3 result of test: null