# Sum of integers in string, separated by non-numericals such as 'a' and 'Y'

Create a program which sums all integers found in a string which is set as a variable in the program (thus, the program doesn't have to handle any input). The integer numbers are separated by non-numericals (anything but 0, 1, 2, 3, ..., 9).

Examples:

• e7rde f ,fe 43 jfj 54f4sD = 7+43+54+4=108
• 5 = 5
• 64 545,5445-32JIFk0ddk = 64+545+5445+32+0=6086
• 0ab0 = 0+0 = 0

Extra notes:

• Unicode support is not necessary, but allowed
• -n (where n is an integer) is not counted as a negative n, but as a hyphen followed by n.

The answer may be printed on the screen (but not required).

• Should we print the result too? (You mention no I/O). Feb 8 '11 at 19:43
• @Dogbert - I didn't think about that. Sorry, yes. I will update the post.
– Anto
Feb 8 '11 at 19:45
• Changed it as some people already had answers and didn't want to "hurt" them. I guess I should sleep now, so I will think a bit clearer ;)
– Anto
Feb 8 '11 at 19:49
• Anto: A task where a solution has no observable side-effects isn't very nice, though.
– Joey
Feb 8 '11 at 21:00
• An interesting test case I just ran into would be 5a-3 (my code would skip - if it follows a number immediately, but not if there was a non-number before it). Sep 1 '15 at 11:48

# Perl - 24 chars

warn eval join'+',/\d+/g


Input is in $_ # SNOBOL4 (CSNOBOL4), 76 bytes  I =INPUT S I SPAN(&DIGITS) . X REM . I :F(O) O =O + X :(S) O OUTPUT =O END  Try it online! ## BASH (v5.0.17) + Unix utils, 40 34 bytes "s" is the string echo${s//[!0-9]/ }|tr ' ' '+'|bc

• tr -Cs 0-9 +|bc, depending on environments, to golf off; input from stdin. Aug 16 at 6:57

## Actually, 14 bytes

9u▀8╙r♂┌-@s♂≈Σ


Try it online!

This program supports the CP437 code page for input.

Explanation:

9u▀8╙r♂┌-@s♂≈Σ
9u▀             base 10 digits (0-9)
8╙r♂┌        all characters in CP437 (map(ord_cp437, range(2**8)))
-       set difference
@s     split input on any value in the resulting list
♂≈Σ  convert to ints and sum


# Vyxals, 8 bytes

\Dṡ';⌊


Try it Online!

Ugh we really need to make ⌊ play nice with strings not containing numbers in v2.6; this would be 6 bytes if it didn't error.

## Explained

\Dṡ';⌊
\D     # The string "\D" (a regex that looks for non-digits)
ṡ    # Split the input on this regex
';  # Remove empty strings (because ⌊ on  errors)
⌊ # Convert each to a number
# Output the sum with the s flag


# Husk, 4 bytes

ṁiġ√


Try it online!

# Explanation

ṁiġ√
ġ√ group on isalpha
ṁ    sum
i   the first integer in each string