Skip to main content
durr, don't need the [ ] since I'm no longer specifying a list of possible matches ...
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 101
  • 283

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 ...

PowerShell, 28 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 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 : 

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 ...

Added an alternate
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 101
  • 283

PowerShell, 28 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 (similarshort 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 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 : 

PowerShell, 28 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 (similar to eval).

PowerShell, 28 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 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 : 
a-zA-Z is equivalent to \D
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 101
  • 283

PowerShell, 3228 bytes

$args-replace"[a-zA-Z]"replace"[\D]",'+0'|iex

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

PowerShell, 32 bytes

$args-replace"[a-zA-Z]",'+0'|iex

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

PowerShell, 28 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 (similar to eval).

Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 101
  • 283
Loading