I have a Javascript string that ends in \n
and I want to remove the last instance of \n
through only regex. So I wrote this query /..$/
which targets it. However, when I run string1.replace(/..$/, "")
the .replace
still returns the original string and does not replace the last instance of \n
with an empty string.
How can I use regex to remove those last two characters?
I've tried this
let string1 = '0,1,2,3,45\n10,11,12,13,14\n20,21,22,23,24\n30,31,32,33,34\n'
string1.replace(/..$/, "")
=> '0,1,2,3,45\n10,11,12,13,14\n20,21,22,23,24\n30,31,32,33,34\n'