PowerShell, 2828 26 bytes
$args-replace"[\D]"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 2828 26 bytes:
$args-split"[\D]"|measuresplit"\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 ...