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!
How 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 July 2026
Contest runs July 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.