Numbers in Strings

Published by Matt in

Create a function that takes an array of strings and returns an array with only the strings that have numbers in them. If there are no strings containing numbers, return an empty array.

Examples

num_in_str(["1a", "a", "2b", "b"]) ➞ ["1a", "2b"]

num_in_str(["abc", "abc10"]) ➞ ["abc10"]

num_in_str(["abc", "ab10c", "a10bc", "bcd"]) ➞ ["ab10c", "a10bc"]

num_in_str(["this is a test", "test1"]) ➞ ["test1"]

Notes

  • The strings can contain white spaces or any type of characters.
  • Bonus: Try solving this without RegEx.
Watch a quick demo on how Edabit works.