I'm using the below code to trim the string based on the condition like 15 characters per line, in this below code, 15 was hard-coded.But I need to make it dynamic like defining variable and pass into replace function.
var str = "Here's to your next step.Keep Walking.Keep Watching"
result = str.replace(/(.{1,15})(?:\n|$| )/g, "$1|\n");
console.log(result);
How I need
var trim_val =15;
var str = "Here's to your next step.Keep Walking.Keep Watching"
result = str.replace(/(.{1,trim_val})(?:\n|$| )/g, "$1|\n"); //here i have to pass that variable
console.log(result);
Thanks in Advance