g | x | w | all
Bytes Lang Time Link
040APLNARS250727T101329ZRosario
213Desmos250726T231815ZErikDaPa
008Vyxal 3250724T172431ZThemooni
061Swift 6240908T003452ZmacOSist
008Uiua231020T005208Zchunes
019AWK250228T170231Zxrs
053Python 3.8240906T133825Zdevoid
034JavaScript Node.js240906T170530Zl4m2
029Arturo240822T135640Zchunes
021J + regex221129T011127Zsouth
031jq R221128T153819Zpmf
020q221128T045909Zcillianr
019Juby221031T173447ZJordan
003Japt v2.0a0 x221102T151519ZShaggy
00305AB1E legacy221102T160237ZKevin Cr
006Pip221102T154524ZDLosc
036Factor + math.unicode sorting.human221031T214015Zchunes
023Ruby n221031T173046ZJordan
004Vyxal s221031T172326Zpacman25
071Python 2160219T141745ZLeeNever
105Oracle SQL 11.2160219T081414ZJeto
043R160218T125818Zslamball
070Python 2160217T094336ZTanMath
029Bash + GNU utilities160212T230828ZDigital
051Lua160215T154913ZKatenkyo
025POSIX sh + tr + dc160215T153450ZToby Spe
045Ruby160215T125047Zryantk
050R160214T220346Zmnel
008MATL160212T154755ZLuis Men
018Perl 6160212T182307ZBrad Gil
035JavaScript ES6160212T182441ZETHprodu
035Clojure/ClojureScript160212T193808ZMattPutn
051Mathematica160212T155858ZA Simmon
106TIBasic160212T182723ZTimtech
035Julia160212T182426ZAlex A.
070Java160212T182235Zhyperneu
008Labyrinth160212T164127ZMartin E
013Seriously160212T171910Zuser4594
004Gol><>160212T171216Zrandomra
002Japt160212T170247ZETHprodu
039Javascript160212T154758Zremoved
013CJam160212T152709ZGamrCorp
064PHP160212T163037Zʰᵈˑ
002GS2160212T162349ZDennis
nanPerl160212T161855ZAndreas
006Jelly160212T155234ZDennis
039Gema160212T161535Zmanatwor
026PowerShell160212T152151ZAdmBorkB
2211Retina160212T153519ZFryAmThe
010Pyth160212T151610ZDoorknob

APL(NARS), 40 chars

{w←'0',⍵⋄+/⍎¨k/⍨{⍵⊆⎕D}¨k←w⊂⍨+\2≠/0,w∊⎕D}

I change the input in the way not find the zilde or void set in the middle of the computation. I find a way to use the partition char '⊂'.

Add to the array of input '0', call that array w, make a partition of w with elements that are or only numbers or only letters, in that partition eliminate elements are formed from letters (element =list of letter), for each in the array result apply command execute (⍎) sum the array result.

test:

  q←{w←'0',⍵⋄+/⍎¨k/⍨{⍵⊆⎕D}¨k←w⊂⍨+\2≠/0,w∊⎕D}
  q'a'
0
  q'0'
0
  q'5'
5
  q'10'
10
  q'a0A'
0
  q'1a1'
2
  q'11a1'
12
  q'4aaaa65uiuou5i5iii'
79

For a speech on easily of read or understand, it seems better use one function that generate partitions not from one array of numbers, but from one binary array... This is my first try, the function p

p←{⍺⊂⍨1++\2≠/0,⍵}    

p has as the array to build the partitions in ⍺, and one array of binary that say where are the borders of partition (where are the ones) in ⍵. It has this input output

  p←{⍺⊂⍨1++\2≠/0,⍵}
  12 13 14 p 0 0 0
┌1──────────┐
│┌3────────┐│
││ 12 13 14││
│└~────────┘2
└∊──────────┘
  12 13 14 p 1 1 1
┌1──────────┐
│┌3────────┐│
││ 12 13 14││
│└~────────┘2
└∊──────────┘
  12 13 15 p 0 1 1
┌2─────────────┐
│┌1──┐ ┌2─────┐│
││ 12│ │ 13 15││
│└~──┘ └~─────┘2
└∊─────────────┘
  12 13 15 p 1 0 1
┌3────────────────┐
│┌1──┐ ┌1──┐ ┌1──┐│
││ 12│ │ 13│ │ 15││
│└~──┘ └~──┘ └~──┘2
└∊────────────────┘
  12 13 15 p 1 1 0
┌2─────────────┐
│┌2─────┐ ┌1──┐│
││ 12 13│ │ 15││
│└~─────┘ └~──┘2
└∊─────────────┘
  12 13 15 p 1 0 0
┌2─────────────┐
│┌1──┐ ┌2─────┐│
││ 12│ │ 13 15││
│└~──┘ └~─────┘2
└∊─────────────┘
  12 13 14 p 0 1 1
┌2─────────────┐
│┌1──┐ ┌2─────┐│
││ 12│ │ 13 14││
│└~──┘ └~─────┘2
└∊─────────────┘
  12 13 15 p 0 1 0
┌3────────────────┐
│┌1──┐ ┌1──┐ ┌1──┐│
││ 12│ │ 13│ │ 15││
│└~──┘ └~──┘ └~──┘2
└∊────────────────┘
  12 13 15 p 0 0 1
┌2─────────────┐
│┌2─────┐ ┌1──┐│
││ 12 13│ │ 15││
│└~─────┘ └~──┘2
└∊─────────────┘

The function above exercise would be:

 S←{w←'0',⍵⋄+/⍎¨k/⍨{⍵⊆⎕D}¨k←w p w∊⎕D} 
 S'4aaaa65uiuou5i5iii'
79
  S'4a'
4
  S'a'
0

Desmos, 213 bytes

m=0^{max(x-58,0)}
H=(x-48)m/m                                                                   => keep only the #s
I=[1...H.count][H=H]                                                          => idxs of #s
k=I.count                                                                        
A=join(0,\left\{k>1:∑_{n=1}^{[1...max(k-1,1)]}sign(I[2...]-I-1)[n],[]\right\}) => grouping mask
D=H[H=H][A=i]                                                                 => at each item in the mask...
f(x)=[total(D10^{[D.count-1...0]})fori=[0...A.max]].total                     => group those #s by the mask and convert to dec, then finally sum

Try this online!

Vyxal 3, 8 bytes

"\d+"⊢E∑

Vyxal It Online!

"\d+"⊢E∑­⁡​‎‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌­
       ∑  # ‎⁡sum
      E   # ‎⁢atoi
"\d+"⊢    # ‎⁣regex matches of /\d+/
💎

Created with the help of Luminespire.

<script type="vyxal3">
"\d+"⊢E∑
</script>
<script>
    args=[["a1wAD5qw45REs5Fw4eRQR33wqe4WE"],["a"],["\"0\""],["\"5\""],["\"10\""],["A0a"],["1a1"],["11a1"],["4dasQWE65asAs5dAa5dWD"],["100a10"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>

Swift 6, 63 61 bytes

{($0+"").split(separator:/[^\d]+/).map{Int($0)!}.reduce(0,+)}

Uiua, 19 12 8 bytes

/+⊜⋕⊸≤@9

Try it!

-7 thanks to Bubbler

AWK, 24 19 bytes

{a+=$1}END{print a}

Attempt This Online!

{for(;i++<NF;)j+=$i}$0=j

Attempt This Online!

There's a little trickery to cause AWK to only process numbers as fields.

Python 3.8, 53 bytes

import re;lambda s:sum(map(int,re.findall(r'\d+',s)))

Attempt This Online!

JavaScript (Node.js), 34 bytes

s=>eval(s.replace(/\D|$/g,' +')+0)

Try it online!

Like ETHproductions's answer but extra push is possible

Not work as intended if leading 0 exist, as it reads as octal

Arturo, 29 bytes

$=>[match&{/\d+}do~"∑|<=|"]

Try it!

J + regex, 21 bytes

1#.0,'\d+'".&>@rxall]

Attempt This Online!

1#.0,'\d+'".&>@rxall]
     '\d+'     rxall]  NB. find all matches of /\d+/ in right arg ]
              @        NB. then execute the monadic verb...
          ".&>         NB. eval each boxed match and unbox result
   0,                  NB. prepend 0 in case of no match
1#.                    NB. sum integer array

If adding the script to the language isn't allowed, then that adds 14 bytes for a total of 35.

1#.0,'\d+'".&>@rxall(load'regex')]]

The only difference is the fork (load'regex')]] that loads the library and simply returns the function arg using dyadic ].

jq -R, 31 bytes

[splits("\\D")|tonumber?]|0+add

Try it online!

q, 41 20 bytes

sum value .Q.n .Q.n?

k, 23 14 bytes

+/. .Q.n .Q.n?

J-uby, 19 bytes

~:scan&/\d+/|:sum+Z

Attempt This Online!

Japt v2.0a0 -x, 3 bytes

'Cause ETH's solution is a bit cheaty!

q\D

Try it

q\D     :Implicit input of string
q       :Split on
 \D     :  RegEx /\D/ (or /[^0-9]/)
        :Implicit output of sum of resulting array

05AB1E (legacy), 3 bytes

á¡O

Try it online or verify all test cases.

In the new version of 05AB1E it would have been 2 bytes longer, because ¡ now supports substrings to split on (in the legacy version a string argument would be interpret as a list of characters implicitly) and will keep empty strings:

áS¡þO

Try it online or verify all test cases.

Explanation:

       # Example input: "a1wAD5qw45REs5Fw4eRQR33wqe4WE"

       # (legacy version)
á      # Only keep the letters of the (implicit) input-string
       #  STACK: "awADqwREsFweRQRwqeWE"
 ¡     # Split the (implicit) input-string on those characters
       #  STACK: ["1","5","45","5","4","33","4"]
  O    # Sum the remaining numbers
       #  STACK: 97
       # (which is output implicitly as result)

       # (new version)
á      # (same as above)
 S     # Split it to a list of characters
       #  STACK: ["a","w","A","D","q","w","R","E","s","F","w","e","R","Q","R","w","q","e","W","E"]
  ¡    # Split the (implicit) input-string on those characters
       #  STACK: ["","1","","","5","","45","","","5","","4","","","","33","","","4","",""]
   þ   # Remove all empty strings, by only keeping numbers
       #  STACK: ["1","5","45","5","4","33","4"]
    O  # (same as above)

Pip, 6 bytes

$+a@XI

Try It Online!

Explanation

    XI  Built-in regex matching integers
   @    Find all matches in
  a     Command-line input
$+      Fold on addition

Factor + math.unicode sorting.human, 36 bytes

[ find-numbers [ real? ] filter Σ ]

Attempt This Online!

                  ! "11a1"
find-numbers      ! { "" 11 "a" 1 }
[ real? ] filter  ! { 11 1 }
Σ                 ! 12

Ruby -n, 23 bytes

Based on Ventero’s answer here.

p eval$_.scan(/\d+/)*?+

Attempt This Online!

Vyxal s, 4 bytes

⁽±Ḋ⌊

Try it Online!

Python 2, 71 bytes

I just had to make one-liner, though it costs a whole byte more than @TanMath's answer

sum(map(int,"".join([i*i.isdigit()or" "for i in raw_input()]).split()))

Explaination:

raw_input()                             - Input
"".join([i*i.isdigit()or" "for i in _]) - Replace non-digits with spaces 
map(int, _.split())                     - Split on spaces, and convert to number
sum(_)                                  - Sum the resulting list

Oracle SQL 11.2, 105 bytes

SELECT NVL(SUM(TO_NUMBER(COLUMN_VALUE)),0)FROM XMLTABLE(('"'||regexp_replace(:1,'[a-zA-Z]','","')||'"'));

The regex convert alpha characters to ','

XMLTABLE create one row per item in the string using ',' as the separator.

SUM the rows to get the result.

NVL is needed to account for a string with no digit.

R, 46 43 bytes

sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))

Explanation

                    scan(,'')                  # Take the input string
           strsplit(         ,'\\D')           # Returns list of all numeric parts of the string
                                    [[1]]      # Unlists to character vector
    strtoi(                              )     # Converts to numeric vector
sum(                                      )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))
1: a1wAD5qw45REs5Fw4eRQR33wqe4WE
2: 
Read 1 item
[1] 97

Edit: Replaced [^0-9] with \\D.

Python 2, 70 bytes

I am putting a Python answer just for fun.

import re
j=0
for i in map(int,re.findall('\d+',input())):j+=i
print j

Very simple and uses regex to find all the numbers in the input. Try it online!

Bash + GNU utilities, 29

grep -Eo [0-9]+|paste -sd+|bc

If it is required to support input with no numbers (e.g. a), then we can do this:

Bash + GNU utilities, 38

1 byte saved thanks to @TobySpeight.

(grep -Eo [0-9]+;echo 0)|paste -sd+|bc

Lua, 51 Bytes

Pretty short for once! Even shorter than Java! The input must be a command-line argument for it to work.

a=0 arg[1]:gsub("%d+",function(c)a=a+c end)print(a)

Ungolfed

a=0                 -- Initialize the sum at 0
arg[1]:gsub("%d+",  -- capture each group of digits in the string
  function(c)       -- and apply an anonymous function to each of them
  a=a+c             -- sums a with the latest group captured
end)               
print(a)            -- output a

POSIX sh + tr + dc, 27 25 bytes

dc -e "0d`tr -sc 0-9 +`p"

Converts any run of non-digits (including the terminating newline) to + operator, pushes two zeros onto the stack (in case input begins with non-digit), adds them all and prints the result. There may be an extra zero remaining at bottom of stack, but we don't care about that.

Ruby 45 bytes

$*[0].split(/[a-z]/i).map(&:to_i).inject 0,:+

(First attempt at work, will revisit this)

R, 50 bytes

Requires having gsubfn installed

sum(gsubfn::strapply(scan(,''),'\\d+',strtoi)[[1]])

Uses strtoi to coerce to numeric

MATL, 8 bytes

1Y4XXXUs

Try it online!

1Y4      % predefined literal: '\d+'
XX       % implicit input. Match regular expression. Returns a cell array of strings
         % representing numbers
XU       % convert each string to a double. Returns a numeric array
s        % sum of numeric array

Perl 6, 18 bytes

{[+] .comb(/\d+/)}
{[+] .split(/\D/)}

Usage:

my &code = {[+] .comb(/\d+/)}

say code 'a'; # 0
say code '0'; # 0
say code '5'; # 5
say code '10'; # 10
say code 'a0A'; # 0
say code '1a1'; # 2
say code '11a1'; # 12
say code '4dasQWE65asAs5dAa5dWD'; # 79
say code 'a1wAD5qw45REs5Fw4eRQR33wqe4WE'; # 97

JavaScript ES6, 35 bytes

s=>eval(s.replace(/\D+/g,'+')+'.0')

How it works

First, we replace each string of non-digits with "+". There are basically four different ways that this could end up:

1. 1b23c456   => 1+23+456
2. a1b23c456  => +1+23+456
3. 1b23c456d  => 1+23+456+
4. a1b23c456d => +1+23+456+

Cases 1 and 2 are taken care of already. But we somehow need to fix the last + so that it doesn't cause an error. We could remove it with .replace(/\+$,""), but that's too expensive. We could append a 0 to the end, but that would affect the last number if the string does not end with a +. A compromise is to append .0, which is both a valid number on its own and doesn't affect the value of other integers.

Here's a few other values that would work as well:

.0
-0
 +0
-""
-[]
0/10
0e-1
.1-.1

Alternate version, also 35 bytes

s=>s.replace(/\d+/g,d=>t+=+d,t=0)|t

Another alternate version, 36 bytes

s=>s.split(/\D/).map(d=>t+=+d,t=0)|t

Clojure/ClojureScript, 35 bytes

#(apply +(map int(re-seq #"\d+"%)))

Mathematica, 51 bytes

Total@ToExpression@StringCases[#,DigitCharacter..]&

Catching the wrong end of the verbose Mathematica builtins. 1 Byte off with the help of @DavidC

TI-Basic, 106 bytes

Works on TI-83/84 calculators!

Input Str1
"{0,→Str2
Str1+"N0→Str1
For(I,1,length(Ans
sub(Str1,I,1
If inString("0123456789",Ans
Then
Str2+Ans→Str2
Else
If ","≠sub(Str2,length(Str2),1
Str2+","→Str2
End
End
sum(expr(Ans

Julia, 35 bytes

s->sum(parse,matchall(r"\d+","0"s))

This is an anonymous function that accepts a string and returns an integer. To call it, assign it to a variable.

We use matchall to get an array consisting of matches of the regular expression \d+, which are just the integers in the string. We have to tack on a 0 to the front of the string, otherwise for cases like "a", we'd be summing over an empty array, which causes an error. We then apply parse to each string match, which converts to integers, and take the sum.

Java, 70 bytes

s->{int n=0;for(String i:s.split("\\D+"))n+=Long.valueOf(i);return n;}

Labyrinth, 8 bytes

Take that, Pyth...

?+
;,;!@

Try it online!

Explanation

The usual primer (stolen from Sp3000):

What comes in really handy here is that Labyrinth has two different input commands, , and ?. The former reads a single byte from STDIN, or -1 at EOF. The latter reads an integer from STDIN. It does so skipping everything that isn't a number and then reads the first decimal number it finds. This one returns 0 at EOF, so we can't use it to check for EOF reliably here.

The main loop of the program is this compact bit:

?+
;,

With ? we read an integer (ignoring all letters), with + we add it to the running total (which starts out as one of the implicit zeroes at the stack bottom). Then we read another character with , to check for EOF. As long as we're not at EOF, the read character will be a letter which has a positive character code, so the IP turns right (from its point of view; i.e. west). ; discards the character because we don't need it and then we enter the loop again.

Once we're at EOF, , pushes a -1 so the IP turns left (east) instead. ; again discards that -1, ! prints the running total as an integer and @ terminates the program.

Seriously, 13 bytes

,ú;û+@s`≈`MΣl

Try it online!

Explanation:

,ú;û+@s`≈`MΣl
,              push input
 ú;û+          push "abc...zABC...Z" (uppercase and lowercase English letters)
     @s        split on letters
       `≈`M    convert to ints
           Σ   sum
            l  length (does nothing to an integer, pushes 0 if an empty list is left, in the case where the string is all letters)

Gol><>, 4 bytes

iEh+

So short I need dummy text...

Japt, 2 bytes

Nx

Test it online!

How it works

N    // Implicit: N = (parse input for numbers, "strings", and [arrays])
x    // Sum. Implicit output.

Javascript, 32 39 bytes

s=>eval((s.match(/\d+/g)||[0]).join`+`)

f=
s=>eval((s.match(/\d+/g)||[0]).join`+`)

F=s=>document.body.innerHTML+='<pre>f(\''+s+'\') -> '+f(s)+'\n</pre>'

F('a')
F('5')
F('10')
F('1a1')
F('11a1')
F('4dasQWE65asAs5dAa5dWD')
F('a1wAD5qw45REs5Fw4eRQR33wqe4WE')

CJam, 13 bytes

Fixed to work with input without numbers thanks to Dennis! Also saved a byte by replacing the letters array with an array of ASCII above code point 64. And then another byte saved by Dennis!

q_A,s-Ser~]1b

Simple transliteration from letters to spaces, then eval and sum. Try it online.

PHP, 64 bytes

<?php preg_match_all("/\d+/",$argv[1],$a);echo array_sum($a[0]);

Run it as

php -f filterOutAndAddUp.php <test_case>

https://eval.in/517817

GS2, 2 bytes

Wd

Try it online!

How it works

W     Read all numbers.
      For input x, this executes map(int, re.findall(r'-?\d+', x)) internally.
 d    Compute their sum.

Perl, 21 + 1 = 22 bytes

$_=eval join"+",/\d+/g

Requires the -p flag:

$ perl -pe'$_=eval join"+",/\d+/g' <<< 'a1wAD5qw45REs5Fw4eRQR33wqe4WE'
97

Jelly, 6 bytes

&-ṣ-ḌS

Try it online!

How it works

&-ṣ-ḌS  Main link. Input: L (string)

&-      Take the bitwise AND of L's characters and -1.
        This attempts to cast to int, so '0' & -1 -> 0 & -1 -> 0.
        On failure, it returns the integer argument (if any), so 'a' & -1 -> -1.
  ṣ-    Split the resulting list at occurrences of -1.
    Ḍ   Convert each chunk from decimal to integer. In particular, [] -> 0.
     S  Compute the sum of the results.

Gema, 39 characters

<D>=@set{s;@add{${s;};$0}}
?=
\Z=${s;0}

Sample run:

bash-4.3$ gema '<D>=@set{s;@add{${s;};$0}};?=;\Z=${s;0}' <<< 'a1wAD5qw45REs5Fw4eRQR33wqe4WE'

PowerShell, 28 26 bytes

$args-replace"\D",'+0'|iex

Takes input $args then does a regex -replace to swap the letters with +0, then pipes that to iex (short for Invoke-Expression and similar to eval).

PS C:\Tools\Scripts\golfing> .\filter-out-and-add-up.ps1 'a1wAD5qw45REs5Fw4eRQR33wqe4WE'
97

Alternatively

If you're OK with some extraneous output, you can do the following, also at 28 26 bytes:

$args-split"\D"|measure -s

This will take the input string $args and -split it into an array-of-strings on the non-numbers (removing them in the process). For example, 1a2b33 would turn into ['1','2','33']. We pipe that to Measure-Object with the -Sum parameter. Output would be like the below:

PS C:\Tools\Scripts\golfing> .\filter-out-and-add-up.ps1 'a1wAD5qw45REs5Fw4eRQR33wqe4WE'

Count    : 21
Average  : 
Sum      : 97
Maximum  : 
Minimum  : 
Property : 

Edit -- durr, don't need the [ ] in the regex since I'm no longer specifying a list of possible matches ...

Retina, 22 11

\d+
$0$*1
1

Try it online!

11 bytes (!) saved thanks to Martin!

Basically just decimal to unary then count the 1s.

Pyth, 12 11 10 bytes

ssM:z"\D"3
    z        autoinitialized to input()
   : "\D"3   split on non-digits
 sM          convert all elements of resulting array to ints
s            sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].

This even allows me to split on every non-digit individually, since 1 + 0 + 0 + 0 + 0 + 2 is the same thing as 1 + 2.

Thanks to Thomas Kwa for a byte!