I'm searching solution how to parse plain text to the js array. I have already found some scheme in which i want to do this, but kind of stuck.
Part of plain text:
2017-11-08 09:43:49,153 [INFO ] root: {\"methodId\":6,\"requestBody\":{},\"token\":\"XXXX\"}2017-11-08 09:53:02,293 [INFO ] root: {\"methodId\":6,\"requestBody\":{},\"token\":\"XXXX\"}2017-11-08 09:53:02,355 [INFO ] root: {\"methodId\":6,\"requestBody\":{},\"token\":\"XXXX\"}
Expected result
const arr = [
'2017-11-08 09:43:49,153 [INFO ] root: {\"methodId\":6,\"requestBody\":{},\"token\":\"XXXX\"}',
'2017-11-08 09:53:02,293 [INFO ] root: {\"methodId\":6,\"requestBody\":{},\"token\":\"XXXX\"}',
'2017-11-08 09:53:02,355 [INFO ] root: {\"methodId\":6,\"requestBody\":{},\"token\":\"XXXX\"}'
]
RegEx Pattern:
/}\d{4}-\d{2}/
Each chunk ends by closing object "}" and starting new date "YYYY-MM".
Problem
plainText.split(/}\d{4}-\d{2}/)
If i split it this way, it always "eats" my separator. Is there some way to split text and add founded separator to the second element from the splited pair? Then i could just add "}" to the first one and remove "}" from the second one. It's solution I'm thinking about, but maybe you can suggest something even better.
s.split(/\b(?=\d{4}-\d{2}-\d{2}\s+[\d:,]+\s+\[INFO ]\s+root:)/).filter(Boolean). Shorten the pattern if the requirements can be lax (depends on the scenario, it can even be/\b(?=\d{4}-\d{2}-\d{2}\s/if the date strings do not appear in the JSON data). See this demo.