I have a use case where the user could paste something in a text area and I'd like to split them based on one of the following use cases:
Problem:
How can I make sure I can catch comma space, comma new line, newline from the string? Would a regex help here?
Context:
I could do
"1, 2, 3".split(', ') // returns [1,2,3]
"1,\n2,\n3,\n".split(',\n') // [1,2,3]
"1\n2\n3\n".split('\n') // [1,2,3]
const formatDataAndReturnArr = (inputString) => {
return inputString.split(', ') // for comma space
}
How do I account all three cases into one? Can we sanitize the input somehow and just return the array?