Given a string that may contain a mix of letters, digits, spaces, and special characters, extract all sequences of consecutive digits and return them as a list of integers in the order they appear.
Return an empty list for null input or input with no digits.
Examples:
Input: input = 'abc 123 def 456'
Output: [123, 456]
Explanation: Two digit sequences found
Input: input = 'Phone: 415-555-1234'
Output: [415, 555, 1234]
Explanation: Each hyphen-separated segment is a separate number
Input: input = 'no numbers here'
Output: []
Explanation: No digit sequences found
Input: input = null
Output: []
Input: input = 'the answer is 42'
Output: [42]
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay May 2026
Contest runs May 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.