Using regex to delete every other line deletes all lines

I have a string that varies in line length that goes in this format::

file/path
hash
file/path
hash

I want to get rid of every line that is a file path and put it into a new variable, and I want to do the opposite, removing every line that isn’t a file path and putting it into a new variable.

Here’s my current solution:

var regex = /\n|.+|\n/
var fixedtochashes = fixedtoc.replace(regex, “”);

This works for the first line, but it only works for the first line. So naturally I added “g” to the end of the regex variable:

var regex = /\n|.+|\n/g
var fixedtochashes = fixedtoc.replace(regex, “”);

And this solution just replaces every line. Anyone know how to fix this?

If I remember right, in variables (and expressions), you need to escape \ characters. So it’s probably not looking correct and just seeing /n and that’s it.

To escape \, you have to duplicate it, so \ and \.

So it’d be like…

 /\\n|.+|\\n/g