Skip to content

Instantly share code, notes, and snippets.

@conmute
Last active February 4, 2019 15:30
Show Gist options
  • Save conmute/17c4f1c6c455a674ce10df0d0a41be02 to your computer and use it in GitHub Desktop.
Save conmute/17c4f1c6c455a674ce10df0d0a41be02 to your computer and use it in GitHub Desktop.
JavaScript Multiple/single line emails into validated and formatted data value… better name?
let str = `
email1@me
email2@me
email3@me;email4@me
`
const parsed = str
.split(';')
.map(line => {
return line
.replace(/[^\S\r\n]+/g, '') // trim
.split(/[\r\n]+/g) // split new lines
.filter(x => !!x) // filter invalid elements, here you can put validation is it email or not
})
.reduce((acc, list) => acc = acc.concat(list), [])
console.log(parsed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment