Extract unique numbers from strings

Problem Each input string contains zero or more embedded numbers (possibly with '-'/'+' signs adjacent, e.g. ["lksmdf-983kjasd78asdkn78", "-234klnsdf+345kmsdf234"]). Extract all numbers across the strings, deduplicated, and return them as integers.

Input / Output

  • Input: list of strings.
  • Output: list of unique integers.

Constraints

  • Clarify: do signs belong to the number (-983 vs 983)? Output order (first-seen vs sorted)? Values exceeding int range?

Example

  • ["a12b12", "-3c"] → sign-aware: [12, -3]; digits-only: [12, 3].
asked …
LeaderboardSalaryAccount
Extract unique numbers from strings · 2dbi