In javascript, If i have a text block like so
Line 1
Line 2
Line 3
What would i need to do to lets say delete the first line and turn it in
I went a bit further to let you be able to select the number of lines from the beginning you want to delete:
I use this regular expression where X is the number of line you want to delete +1 (?:.*?\n){X}(?:.*?\n)
const lines = `Line1
Line2
Line3
Line4`;
const deleteLines = (string, n = 1)=>{
return string.replace(new RegExp(`(?:.*?\n){${n-1}}(?:.*?\n)`), '');
};
console.log(deleteLines(lines, 2));