Regular Expressions

Flashcard 8 of 10

How can we select only the elements in an array that match a given regex?

valid_email = /.+@.+\..+/

possible_emails = [
  "user@example.com",
  "person@thing",
  "ben@upcase.com",
  "user@place.it",
  "asdf"
]

<your code here, using valid_email>
#=> [
#     "user@example.com",
#     "ben@upcase.com",
#     "user@place.it"
#   ]

Answer:

Reveal Answer