I have a text file containing a mixture of characters, empty lines, and the values I want to pluck out - numbers which are separated either by linebreaks and, for backwards compatibility, as comma separated values.
# Here are some numbers such as 34 and 53
34
53
124
# Here's a number
45
44
# And a final number
72
# And here's a legacy set of comma separated numbers
23,24,25
So far I've managed to pluck the numbers out by reading the file in and using a match to split them out to an array:
input.match(/^([0-9]+[^\r\n]?)+$/gm)
// ["34", "53", "124", "45", "44", "72", "23,24,25"]
Unfortunately I'm struggling to get the regex to split the comma separated numbers as well. What I want to achieve is getting that final set of numbers to split into their own values:
["34", "53", "124", "45", "44", "72", "23", "24", "25"]
Dropping a comma in alongside the linebreaks in the regex doesn't do the trick, and I think I've reached the limits of my regex knowledge, so any help appreciated in working this one out!
Regex101 example: https://regex101.com/r/rmpmuD/1