I am trying to split an imported text file into an array based on the fact each line starts with a date in the format DD/MM/YYYY. I have tried using regex to achieve this:
flist = f.split(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/)
with f being the string to split. However the code runs and produces an array saved to flist and when console.log(flist) is run it only has one element and has not been split up.
edit:
Full code:
const fs = require("fs")
f = fs.readFileSync("file.txt", "utf8")
let flist = f.split(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/g)
console.log(flist)
example file.txt:
18/07/2018, 18:04 - Person2: message
18/07/2018, 18:04 - Person1: Yes
18/07/2018, 18:04 - Person2: That's good then
18/07/2018, 18:05 - Person1: message line 1
message line 2
18/07/2018, 18:05 - Person2: text
18/07/2018, 18:05 - Person2: But nvm
18/07/2018, 18:06 - Person1: text
So the issue with splitting with new line is that a new line doesn't mean a new message however i want my array to be each new message so therefore need each new element to start with DD/MM/YYYY an am searching to split with that with regex however it is not splitting/finding a match.
let [_, day, month, year] = f.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);?let res = f.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/).slice(1);? Note.split(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/).filter(Boolean)works, too./gbe missing?