[Question]
  [
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).
Shortest answer (in characters) win.
  
[Answer]
## Ruby 1.9, 21 characters
```
eval a.scan(/\d+/)*?+
```
To print the solution to stdout, 2 additional characters are required:
```
p eval a.scan(/\d+/)*?+
```
And to read from stdin instead of using a predefined variable, another 3 characters have to be used:
```
p eval gets.scan(/\d+/)*?+
```
For Ruby 1.8, replace `?+` with `"+"` to get a working solution in 22 characters.
[Answer]
## Perl, 15
Input in `$_`, sum in `$c`:
```
s/\d+/$c+=$&/ge
```
[Answer]
# Ruby - 36 34 chars
```
s.scan(/\d+/).map(&:to_i).reduce:+
```
36 chars if you want the result printed.
```
p s.scan(/\d+/).map(&:to_i).reduce:+
```
Assumes the input is present as a string in s.
[Answer]
## Python (60)
```
import re;print sum(map(int,filter(len,re.split(r'\D',s))))
```
[Answer]
# JavaScript (ES6), 30
```
c=0,s.replace(/\d+/g,d=>c+=+d)
```
Annotated version:
```
// Store the sum.
c=0,
// Process every number found in the `s`.
s.replace(/\d+/g,
  // Convert the number into an integer.
  // Add it to the sum.
  d => c += +d
)
```
[Answer]
## Windows PowerShell, 23 ~~25~~ ~~29~~ ~~31~~
With output.
```
$x-replace'\D','+0'|iex
```
In fact, without output is exactly the same, you'd just pipe it somewhere else where it's needed.
[Answer]
# gs2, 4 bytes
```
W#Θd
```
Encoded in [CP437](https://en.wikipedia.org/wiki/Code_page_437); the third byte is `E9`.
`W` reads all numbers `/-?\d+/` from a string, `#Θ` maps absolute value, `d` sums.
*(gs2, too, is newer than this challenge, but its `read-nums` command is a total coincidence.)*
[Answer]
# JavaScript [31 bytes]
```
eval(s.match(/\d+/g).join('+'))
```
[Answer]
## J - 40 38 characters
Lazy version. Requires the string library.
```
+/".(,' ',.~a.-.'0123456789')charsub y
```
[Answer]
## Java
out of the contest ;)
```
public static long sum(String s) {
    long sum = 0;
    String p = "";
    char[] ch = s.toCharArray();
    for (int i = 0; i < ch.length; i++) {
        boolean c = false;
        if (Character.isDigit(ch[i])) {
            if (i + 1 < ch.length) {
                if (Character.isDigit(ch[i + 1])) {
                    p += ch[i];
                    c = true;
                }
            }
            if (!c) {
                p += ch[i];
                sum += Integer.valueOf(p);
                p = "";
                c = false;
            }
        }
    }
    return sum;
}
```
[Answer]
# [Labyrinth](https://github.com/mbuettner/labyrinth), ~~29~~ 21 bytes
*(Disclaimer: Labyrinth is newer than this challenge.)*
Also, Labyrinth doesn't have variables, so I went with a normal input/output program.
```
)_"+`
( "?"
";;,;;(!@
```
This was fairly simple because of the way Labyrinth's input commands work. `?` tries to read a signed integer from STDIN and stops at the first non-digit. If it can't read an integer (because the next character is a `-` not followed by a digit, or any other non-digit, or we've reached EOF), it will return `0` instead. `,` on the other hand reads any subsequent byte and pushes the byte value. If this one is called at EOF it will return `-1` instead.
So here's some pseudocode for the solution:
```
running total = 0
while(true)
  while(true)
    try reading a non-zero integer N with ?
    if(N < 0)
      running total -= N
    else if(N > 0)
      running total += N
    else
      break
  // We've either read a zero or hit a something that isn't a number
  try reading a character with ,
  if(that returned -1)
    break
print running total
```
Dealing with negative numbers correctly complicates this solution quite a lot. If it weren't for those, I'd have this 8-byte solution:
```
?+
;,;!@
```
[Answer]
# [Perl 5](https://www.perl.org/) `-MList::Util=sum -pF/\D+/`, 8 bytes
```
$_=sum@F
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3ra4NNfB7f9/MxMFUxNTHVMTE1NdYyMvT7dsg5SU7H/5BSWZ@XnF/3V9fTKLS6ysQksyc0Ba/usW/Nd1049x0dYHAA "Perl 5 – Try It Online")
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/wiki/Commands), 5 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
.œþOà
```
[Try it online](https://tio.run/##MzBNTDJM/f9f7@jkw/v8Dy/4/z/VvCjF0ChVwdAwzQAA) or [verify a few more test cases](https://tio.run/##MzBNTDJM/V9TVmmvpPCobZKCkn3lf72jkw/v8z@84L/O/1TzohRDo1QFQ8M0Ay5TLoPEJAMuMxMFUxNTHVMTE1NdYyMvAA). (Times out for the larger test cases due to the `.œ` builtin.)
**Explanation:**
```
.œ     # Get all partitions of the (implicit) input-string,
       # which are all possible ways of dividing the input-strings into substrings
  þ    # Only leave the items consisting of digits for each partition
       # (in the new version of 05AB1E, an explicit `€` is required)
   O   # Sum each inner list
    à  # Pop and push its maximum
       # (after which the result is output implicitly)
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + GNU utilities, 24 bytes
```
dc<<<`tr -c 0-9 +<<<$s`p
```
[Try it online!](https://tio.run/##JYvNCoJAHMTvPcUgwh5qYdsPTbBOEdRTuO4HpqDhdvDtt790mPnNMExv05DjsiLhPYOFevUBETjFAK0wxhFGR53uDMyQKk3dnIzWhiv5ej4m4f1Eg7C9INia7NLYPSbfnGXycc@q138YR1RbJQlaqm1zUiRv2QHwCxkQ3LCAzyjKhOsNRfaubdvuu4I7CN7gSLVM3SfvlznkHw "Bash – Try It Online")
Input in the variable `s`, output on `stdout`.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 7 bytes
```
$+a@+XD
```
[Try it online!](https://tio.run/##K8gs@P9fRTvRQTvC5f///6nmRSmpCmkKCjppqQomxgpZaVkKpiZpJsUu/3ULAA "Pip – Try It Online")
Regexes all numbers to a list and sums them.
+1 byte fix from DLosc.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `s`, 6 bytes
```
`\D`ṡ⌊
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJzIiwiIiwiYFxcRGDhuaHijIoiLCIiLCJlN3JkZSBmICAsZmUgNDMgamZqIDU0ZjRzRCJd)
~~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.~~ 2.6 done did make the change lol.
## Explained
```
`\D`ṡ⌊
`\D`   # The string "\D" (a regex that looks for non-digits)
    ṡ  # Split the input on this regex
     ⌊ # Convert each to a number
       # Output the sum with the `s` flag  
```
[Answer]
# PHP - 37
Without printing;
```
<?array_sum(@split("[^0-9]+",`cat`));
```
With printing (38):
```
<?=array_sum(@split("[^0-9]+",`cat`));
```
[Answer]
## Perl, 16 chars
```
s/\d+/$r+=$&/ge;
```
Takes input in `$_`, output goes on `$r`. Last semicolon is superfluous, but it will probably be needed when the program does more things. Add `say$r` for output.
[Answer]
## R, 30
```
sum(scan(t=gsub("\\D"," ",x)))
```
Here, `x` is the name of the variable.
Example:
```
> x  <- "e7rde f ,fe 43 jfj 54f4sD"
> sum(scan(t=gsub("\\D"," ",x)))
Read 4 items
[1] 108
```
[Answer]
# J - 23 char
Not a winner, but we get to see a fairly rare primitive in action.
```
+/".(,_=_"."0 y)}y,:' '
```
Explained:
* `_"."0 y` - For each character in the input string `y`, try to read it in as a number. If you can't, use the default value `_` (infinity) instead.
* `,_=` - Check each result for equality to `_`, and then run the final array of 0s and 1s into a vector. (`"."0` always adds one too many dimensions to the result, so we correct for that here.)
* `y,:' '` - Add a row of spaces beneath the input string.
* `}` - Used as it is here, `}` is called *Item Amend*, and it uses the list of 0s and 1s on the left as indices to select the row to draw from in the right argument. So what happens is, for each column in the right side, we take the original character if it could be read in as a number, and otherwise we take the space beneath it. Hence, we cover up any non-numeric characters with spaces.
* `+/".` - Now convert this entire string into an list of numbers, and sum them.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 9 bytes
```
{~cịˢ+}ᶠ⌉
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3wv7ou@eHu7tOLtGsfblvwqKfz//9oJVMlHSWDxCQDIGVqkmZS7AJkmJjqGht5eQJZOfnlufHmSrEA "Brachylog – Try It Online")
It's... inefficient... so I've neglected to test the longer cases. It appears to work, though. Takes input through the input variable, which just so happens to be the usual form of input anyhow.
```
        ⌉    The output is the largest
{     }ᶠ     possible
     +       sum of
   ịˢ        integers the string representations of which are some elements of
 ~c          a partition of the input.
```
`⌉` ensures that numbers are maximally matched as well as never negative, since splitting a number up, invalidating a number, or turning it negative will never result in a larger sum.
[Answer]
# C 96
**Thanks to @ceilingcat for some very nice pieces of golfing - now even shorter**
```
t;main(i,v)int**v;{for(char*q,*s=v[1];*s;q>s?t+=abs(i),s=q:s++)i=strtol(s,&q,0);printf("%d",t);}
```
[Try it online!](https://tio.run/##DcxLCsIwEADQq4SCks8IihHBIbrxFuIipo2maGsyQzbi2aPvAC@s7iG0xvjyaZIJqkoTa13xE@ciw8MXnUGTq5fNFTVhPtKJjfM3kkkBuXwgY1RyxIXnpyRYZlgrfJd/E2W36Dtghd/W2rAv/SCiEBAHYbdijKPY2Wjp/AM "C (gcc) – Try It Online")
An earlier 85 byte version that is cheating a bit by hardcoding the string inside the program:
```
t=0;main(i){for(char*q,*s;i=strtol(s,&q,0),*s;q>s?t+=abs(i),s=q:s++);printf("%d",t);}
```
To actually use the 85 byte program you need to assign the variable like so:
```
t=0;main(i){for(char*q,*s="text";i=strtol(s,&q,0),*s;q>s?t+=abs(i),s=q:s++);printf("%d",t);}
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 8 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
µÖ▀o)♫⌐ƒ
```
[Run and debug it](https://staxlang.xyz/#p=e699df6f290ea99f&i=%22e7rde+f++,fe+43+jfj+54f4sD%22%0A%225%22%0A%2264+545,5445-32JIFk0ddk%22%0A%220ab0%22&a=1&m=2)
Finds all substrings matching `\d+`, then `eval` and sum.
[Answer]
# [Funky](https://github.com/TehFlaminTaco/Funky), 38 bytes
```
s=>{n=0forv ins::gmatch"\\d+"n-=-v[0]}
```
## Explained
```
s=>{                                 } $# A function taking argument "s"
    n=0                                $# Preset n to 0
              s::gmatch"\\d+"          $# An iterator function which finds all groups of digits in a string
       forv in                         $# Iterate through, setting v to the match
                             n-=       $# Subtract n by
                                -v[0]  $# The negative of the whole match, which implicitely numberfies it.
                                       $# Conveniently implcit return from last statement in the function.
```
[Try it online!](https://tio.run/##TYvdCoIwGECv8yk@BoKSgj9bgTCvuuoVVNBsX2k0y00hxGdff2DdHQ7n4CAvD4PcKJ5OkgfY9SM0UiXJ6Vrp@kzy/Lgm0uf@mAXFbHCQtW46CVoo7dSVEu5krW59IzU4ZUbsO7Hftsg1TyHDb1KUrjVbn4WIbX8UgAAeCqAxtNgCo0jVjrh/SRgJCEMMFskWCqrDT2/o62Yeo5T5cbQnrnkC "Funky – Try It Online")
[Answer]
## Actually, 14 bytes
```
9u▀8╙r♂┌-@s♂≈Σ
```
[Try it online!](http://actually.tryitonline.net/#code=OXXiloA44pWZcuKZguKUjC1Ac-KZguKJiM6j&input=ImU3cmRlIGYgICxmZSA0MyBqZmogNTRmNHNEIg)
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
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) v2.0a0 [`-x`](https://codegolf.meta.stackexchange.com/a/14339/), 3 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
q\D
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=2.0a0&flags=LXg&code=cVxE&input=ImU3cmRlIGYgICxmZSA0MyBqZmogNTRmNHNEIg)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
ṁiġ√
```
[Try it online!](https://tio.run/##yygtzv7//@HOxswjCx91zPr//3@qeVFKqkKagoJOWqqCibFCVlqWgqlJmkmxCwA "Husk – Try It Online")
# Explanation
```
ṁiġ√
  ġ√ group on isalpha
ṁ    sum
 i   the first integer in each string
```
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-n`, 26 bytes
```
p eval"#$_ 0".gsub /\D/,?+
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpclm0km6eUuyCpaUlaboWuwoUUssSc5SUVeIVDJT00otLkxT0Y1z0dey1IQqg6hbctEg1L0pJVUhTUNBJS1UwMVbISstSMDVJMyl24TLlMjMBsk11TE1MTHWNjbw83bINUlKyuQwSkwwgBgAA)
Appends  `0` to the input, replaces each non-digit with `+`, then evals.
[Answer]
# [K4](https://kx.com/download/), ~~21~~ 14 bytes
**Solution:**
```
+/. .Q.n .Q.n?
```
**Explanation:**
With thanks to @cillianreilly - I didn't expect a string of numbers to be tokenised with `value`.
```
+/. .Q.n .Q.n? / the solution
         .Q.n? / lookup right in the string "0123456789"
    .Q.n       / index back into "0123456789"
  .            / 'value', tokenises string into integers
+/             / sum up
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 12 bytes
```
S`\D
.+
$*
.
```
[Try it online.](https://tio.run/##K0otycxL/K@q4Z7wPzghxoVLT5tLRYtL7///VPOilFSFNAUFnbRUBRNjhay0LAVTkzSTYhcuUy4zEyDbVMfUxMRU19jIy9Mt2yAlJZvLIDHJAAA)
**Explanation:**
Split on non-digit characters, putting each number on its own separated line:
```
S`\D
```
Convert each number to unary, and implicitly remove the newlines:
```
.+
$*
```
Convert it from unary back to an integer, which is output implicitly as result:
```
.
```
]