I have a string like hey! <input/>, Welcome in a template.
I need to replace every <input/> with the a JS expression this.input.
eg:
//Input
"hey! <input/>, Welcome";
Output should be:
"hey! " + this.input + ", Welcome";
I can do a replace on the string with " + this.input + " but the problem is what if <input/> at the start or the end?
What is the best way to handle this?
Edit:
I don't want the output to be a string. I want the output to be a valid JS expression.
Valid inputs:
1) "hey! <input/>, Welcome";
2) "<input/>, Welcome";
3) "Welcome <input/>"
Outputs:
1) "hey! " + this.input + ", Welcome";
2) this.input + ", Welcome";
3) "Welcome " + this.input;
"hey! <input/>, Welcome".replace(/<input\/>/g, '" + this.input + "');will give you"hey! " + this.input + ", Welcome". Like that?