I have a node script that reads another js file, and I want to get the value of a specific variable in that js file. As I can imagine, there are way better solutions to solve exactly my problem, but I want a function, that I can use again later on, in for example web-apps.
I need a function, that returns the string between a X string and a Y string. For example:
const string2searchin = "<random text with unknown length> /start/ i want to be selected /end/ <random text with unknown length>"
How can I get the string that is between "start" and "end"? The length of the random text it is between is not known.
I've tried this:
var getText = (string, start, end) => {
let arr = string.split("");
let listen = false;
let output = [];
for(let el of arr){
if(el == end && listen) return output.toString();
if(listen) output.push(el);
if(el == start && !listen) listen = true;
}
}
It works just fine, but only with single characters. I want to have string with a length greater than 1 as a start and as an end.