[Question]
  [
# Challenge
Given a string of any length which contains only digits from `0` to `9`, replace each consecutive run of the digit `0` with its length.
## Test Cases
1. `1234500362000440` → `1234523623441`
2. `123450036200044` → `123452362344`
3. `000000000000` → `12`
4. `0123456789` → `1123456789`
5. `1234567890` → `1234567891`
6. `123456789` → `123456789`
7. `010203004050` → `11121324151`
## Note
The shortest answer in bytes wins as per [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules
  
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 6 bytes
```
0+
$.&
```
[Try it online!](https://tio.run/##K0otycxL/P/fQJtLRU/t/39DI2MTUwMDYzMjAwMDExMDLjQBLgMkwGUAljUzt7DkgrMMEEygvIGRgTFQn4GpAQA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation: Unary to decimal conversion.
[Answer]
# JavaScript, 31 bytes
```
s=>s.replace(/0+/g,x=>x.length)
```
[Try it online!](https://tio.run/##BcHhDkAgEADg16khJ/Evz6LlCrtVKzNvf77vdq9rvl7lGVI@kIPlZremKhZyHsUI3Rj7z26fIkzxOSX7nFomVJSjCGKf9GwWgHnVAGAM7FLyDw)
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 7 bytes
-1 byte by jezza\_99 / DLosc
```
aR+X0#_
```
Wow pip is really good at regex
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCJhUmAwK2AjXyIsIiIsIjEyMzQ1MDAzNjIwMDA0NDAiLCIiXQ==)
```
aR+X0#_
aR+X0     Replace all occurrences of (regexified zero with a +)
     #_   with it's length
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 7 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
r+iT Èl
```
[Try it here](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=citpVCDIbA&input=IjEyMzQ1MDAzNjIwMDA0NDAi)
```
r+iT Èl     :Implicit input of string
r           :Replace
 +i         :  "+" prepended with
   T        :    0, giving the RegEx /0+/g
     È      :  Pass each match through a function
      l     :    Length
```
[Answer]
# [QuadR](https://github.com/abrudz/QuadRS), 5 bytes
```
0+
⍵L
```
[Try it online!](https://tio.run/##KyxNTCn6/99Am@tR71af//8NjYxNTA0MjM2MDAwMTEwMuNAEuAyQAJcBWNbM3MKSC84yQDCB8gZGBsZAfQamBgA "QuadR – Try It Online")
`0+` Replace any runs of zeros
`⍵L` with the match Length
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `s`, 7 bytes
```
ĠṠƛ0cßL
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJzIiwiIiwixKDhuaDGmzBjw59MIiwiIiwiXCIwMDExMTFcIiJd)
## Explained
```
ĠṠƛ0cßL
Ġ       # Group on consecutive items
 Ṡ      # join each into a single string
  ƛ     # To each group:
   0c   #   if it contains 0:
     ßL #     push the length of the string
        # the s flag joins into a single string
```
An alternate 8 byter that uses regex match replacement
```
‛0+$⁽Løṙ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLigJswKyTigb1Mw7jhuZkiLCIiLCJcIjEwMDAwMDAwMVwiIl0=)
## Explained
```
‛0+$⁽Løṙ
‛0+       # The string "0+"
   $      # pushed under the input
    ⁽L    # a function object that returns the length of its argument
      øṙ  # replace instances of runs of 0 with their length
```
[Answer]
# ><>, 55 bytes
```
i:'0'= ?v>:0(?;o
='0':i<1<\n$v?
      \+1~  /
```
[Try it](https://mousetail.github.io/Fish/#eyJ0ZXh0IjoiaTonMCc9ID92PjowKD87b1xuPScwJzppPDE8XFxuJHY/XG4gICAgICBcXCsxfiAgL1xuICAgICAgICAgIiwiaW5wdXQiOiIxMDAxIiwic3RhY2siOiIiLCJtb2RlIjoibnVtYmVycyJ9)
[Answer]
# [Python 3](https://docs.python.org/3/), ~~91~~ 90 bytes
```
lambda x:''.join(l>"0"and l or f'{len([*g])}'for l,g in groupby(x))
from itertools import*
```
[Try it online!](https://tio.run/##dcuxDsIgFIXh3ae46QI0xlxLdTDRF1EHmhbEAJcgJm2Mz46MOnjG/8uJS75RkEUfL8UpP4wK5gNjmzvZwN2pwUaFERxQAs1ebgr83JqreDNdi1sbsAFMomccFj4LsdKJPNg8pUzkHmB9pJTbEpMNmWvOtp3sd4hy3yFi3yOrn3/4Y/i1CuUD "Python 3 – Try It Online")
*-1 byte thanks to The Thonnu*
I use the `itertools` module's `groupby` function to group consecutively.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
0ÃηRāR:
```
[Try it online!](https://tio.run/##yy9OTMpM/f/f4HDzue1BRxqDrP7/NzQyNjE1MDA2MzIwMDAxMQAA "05AB1E – Try It Online")
* -6 thanks to Kevin Cruijssen
#### Explanation
```
0ÃηRāR:   # Implicit input
0Ã        # List intersection with [0]
  ηR      # Reversed prefixes
    āR    # Reversed length range
      :   # Infinite replacement
```
Previous 13 byte answer
```
.γ}εD0.åig}}J   # Implicit input
.γ}             # Group by consecutive items
   ε       }    # For each group:
    D           #  Duplicate the group
     0.åi }     #  If 0 is in the group:
         g      #   Push its length
            J   # Join everything into a single string
```
[Answer]
# [R](https://www.r-project.org), ~~64~~ ~~58~~ 57 bytes
*Edit: -1 byte thanks to [@Dominic van Essen](https://codegolf.stackexchange.com/users/95126/dominic-van-essen)*.
```
\(x){regmatches(x,t)=Map(attr,t<-gregexpr("0+",x),"m")
x}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=ddBLCsIwFAVQnLqKEAdJMMLLp7aCXYI7cFKkrROx1BQC4kqcVMFF6WqMTf23bxLCPQk3OZ7K-pzFl8pkk-g6W1LL9mWabxKzWqc7arlh8SIpaGJMyc18krswtUVJMYwxt4zjDWZDe_AX3AZhRomQSgcAaioBQGsgbIS2lSkqg2LkU-lCpbUgw39PUK9vOHwMQW5-uEfNsWkYzRryi97pq8BjB534mYpv3Noe3LYACco9CoKuqq6GUFKLQBD_f3Xt1zs)
`R` has some weird string manipulation functions...
[Answer]
# [Raku](https://raku.org/), 18 bytes
```
{S:g[0+]=$/.chars}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/OtgqPdpAO9ZWRV8vOSOxqLj2f3FipYKSSryCrZ1CdZqCSnytkkJafpGCjaGRsYmpgYGxmZGBgYGJiYECmoCCARJQMADLmplbWCrAWQYIJlDewMjAGKjPwNTA7j8A "Perl 6 – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 16 bytes
```
s/0+/length$&/eg
```
[Try it online!](https://tio.run/##K0gtyjH9r6xYAKQVdAv@F@sbaOvnpOall2SoqOmnpv//b2BoYGRgbGBgYmBqAAA "Perl 5 – Try It Online")
[Answer]
# [Vim](https://github.com/DJMcMayhem/V), 28 bytes
`:s/0\+/\=len(submatch(0))/g`
`Enter`
[Try it online!](https://tio.run/##K/v/36pY3yBGWz/GNic1T6O4NCk3sSQ5Q8NAU1M/nev/f0MjYxNTAwNjMyMDAwMTEwMkAAA "V (vim) – Try It Online")
We cannot use `0*` because it matches the empty string between digits.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 8 bytes
```
(0+)
$.1
```
[Try it online!](https://tio.run/##K0otycxL/P9fw0Bbk0tFz/D/fwNDAyMDYwMDEwNTAwA "Retina 0.8.2 – Try It Online")
### How it works
Match runs of zeros (`0+`), capture each match in a group (`( )`), replace it with the length of the most recent capture (`$.1`).
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 28 bytes
```
0i:"0"=?v{:?n}ol?!
~1+00.  >
```
[Try it online!](https://tio.run/##S8sszvj/3yDTSslAyda@rNrKPq82P8dekavOUNvAQE9Bwe7/f0MjYxNTAwNjMyMDAwMTEwMA "><> – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 16 bytes
```
gsub /0+/,&:size
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpclm0km6BUuyCpaUlaboWG9KLS5MU9A209XXUrIozq1IhwlDZBXsNjYxNTA0MjM2MDAwMTEwMuAwMDYwMjIFsA1MDiCIA)
[Answer]
# [Python](https://www.python.org), ~~62~~ 57 bytes
```
lambda n:re.sub("0+",lambda s:str(len(s[0])),n)
import re
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3LXMSc5NSEhXyrIpS9YpLkzSUDLSVdKCCxVbFJUUaOal5GsXRBrGamjp5mlyZuQX5RSUKRakQA24x8hYUZeaVaKRpqBsaGZuYGhgYmxkZGBiYmBioa9raQgSNgGLGJiaG6ppcuFRjKEZWa4AEoApRpMH6zMwtLCGSSFw0-0CCSO4CcTEdhTAImzkGhgZGBsZAJxuYQk0C2mdobGRiaAo0ChIqCxZAaAA)
-5 bytes thanks to @xnor
Regex solution, port of [@mathcat's Pip answer](https://codegolf.stackexchange.com/a/255826/110555)
[Answer]
# Bash - ~~181~~ 158 chars
*Edit 1: I used [this trick](https://codegolf.stackexchange.com/a/25802/116162) for the `for` loop, remove whitespace, condence an `if` statement*
```
n=0;for ((i=0;i<${#1};i++));{ c="${1:$i:1}";if [ $c = '0' ]; then ((n++)); else [ $n -ne 0 ] && { echo -n $n;n=0;};echo -n $c;fi;};[ $n -ne 0 ] && echo -n $n
```
## Explanation
```
# a counter of how far into a sequence of zeros we are
# this is zero if we're not in a 'zero-sequence'
n=0
# iterate over all the characters
# $1 is the first function argument ($0 would be the script name)
for (( i=0; i<${#1}; i++ )); do
    # get the current char
    c="${1:$i:1}"
    # if it is a zero, then increment the counter
    if [ $c = '0' ]; then
        ((n++));
    # if it is NOT a zero
    else
        # if a zero sequence is over (given that the counter is
        # not equal to zero and the current char isn't zero)
        if [ $n -ne 0 ]; then
            # print the number of zeros in the sequence,
            # and reset the counter to zero
            echo -n $n;
            n=0;
        fi;
    echo -n $c;
    fi
done
# check if there was a zero sequence terminating the string,
# as we wouldn't otherwise check as there wouldn't be a non-zero
# char initiating the check
if [ $n -ne 0 ]; then echo -n $n; fi
```
I referred to [this SO answer](https://stackoverflow.com/a/10552175/20827475) for how to iterate over a string in Bash and [this AU answer](https://askubuntu.com/a/385532/1659062) for a short way to increment a variable
[Answer]
# Excel VBA, ~~100~~ 77 bytes
Saved 23 bytes thanks to a translation by [Taylor Raine](https://codegolf.stackexchange.com/questions/255822/replace-0s-in-a-string-with-their-consecutive-counts/255867?noredirect=1#comment572654_255867)
```
For i=2^15-1To 1Step-1:[B1]=i:[A1]=[Substitute(A1,Rept(0,B1),B1)]:Next:[B1]="
```
Input is in the cell `A1` of the active sheet. Output is in the same cell. The code is run from the immediate window in VBA. The only clever bit is that Excel only allows 32,767 characters in a cell and counting down from there is less bytes than counting down from the length of the input.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 25 bytes
```
{,/$(.'x)|#'x:(&~=':x)_x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxtkN1OgzAYhs97Fc1chCV2LQXmhHjkLXi2LI7UAs0QJu20y3SHXoCX6JVYfuRnjqN+7/f0LXni4HiDp/bc0rOPK0sH9vXp3gr07El/AqCC43R1OJVBDCHU4abYhvYmjkQW6vAQlrN1xawmDnU9nxB3QQkhnkcmYRNRk7ie50zWF6gzqGHI4KuBNq7Jxe3yrgr7oe+txu7danDOlsPdXymhxDW/Qvz6pul1XOo5fnUVAAxSpXYywJgVzzwpsnguVcS2XLM0yhM+Z8ULft1zqUSRS0x9f0kpLvkuixhHRCKRowhJVYo8Qe9CpUilXJSIGZqzvRJv3Jz3uZIAPJoW+BBJbs7GNDwXCn++vuFI6SXsH1VDQ6Ut0eSdjibtxr66ltq31lrH2/Gy7e21ts2dWAB+AUx2mz8=)
* `x:(&~=':x)_x` split the input where it changes, and reassign to `x`
* `(.'x)|#'x` take the maximum of the chunk of input (converted to its corresponding integer) and its count
* `,/$` convert to strings and flatten (and implicitly return)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 70 bytes
```
n;f(char*a){*a-48?n=!printf(n?"%d":"%c",n?:*a++),*a&&f(a):f(a+!!++n);}
```
[Try it online!](https://tio.run/##FcnBCsIwDADQb2lgI2k2iFsV6ZB@S4hUdzCM4W347VUv7/JsfJi15ktFe@oelY6oY7oWv4VtX/1d0Qt0d8jQGQxeclRmGqL2fUWl/INDYHZaPu2lqyMdFeE0zeksMl8mEUlJ4N9f "C (gcc) – Try It Online")
# [C (gcc)](https://gcc.gnu.org/), 62 bytes by c--
```
n;f(int*a){*a-48?n=!printf(n?"%d":a++,n),*a&&f(a):f(a+!!++n);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z/POk0jM69EK1GzWitR18TCPs9WsaAIKJKmkWevpJqiZJWora2Tp6mjlaimlqaRqGkFJLQVFbW18zSta//nJmbmaWhWp2n4KBkaGZuYGhgYmxkZGBiYmBgogeQB "C (gcc) – Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), 27 bytes
```
!x=replace(x,r"0+"=>length)
```
[Try it online!](https://tio.run/##fY9fa4MwFMXf8ymuMoiybtz80W4D@7ZPMcaINesyQioawYd@dxfr7Cptd8lDOOf8Lud@d9Yo1g9D1BeNrq3a6qRfNTHex8XGarfzX@nwuW/AgHHQaFVZ43SbpATCfKx@n5o/JRTQ1tb4xEwRFQT1xl@0qx7Y@1EaM@VSqhvjvHWJKjaRmsAokCEHh8PJjV/7Wm@9ruCujFMS@IE9QuuDvQs7KeNCZogi54goJVLYd77u/MnjwRJSMkr4PxyFGxwl4hzDs6Fj5QVGiVyEj4vy9dPzFF2E/zySXRQbdbwCzV64Jr8Kzcw1iJL1sh1yFOF4zC5PCfWY4JJljP4A "Julia 1.0 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Œgċ”0ȯƊ€
```
A full program that accepts a string of digit characters and prints the result.
**[Try it online!](https://tio.run/##y0rNyan8///opPQj3Y8a5hqcWH@s61HTmv///6sbGhmbmBoYGJsZGcCBiYk6AA "Jelly – Try It Online")**
### How?
```
Œgċ”0ȯƊ€ - Main Link: list of characters, S
Œg       - group runs
       € - for each group:
      Ɗ  -   last three links as a monad - f(group):
   ”0    -     literal '0' character
  ċ      -     count occurrences
     ȯ   -     logical OR (group)
         - implicit, smashing print
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 8 bytes
```
ṁ?IosLig
```
[Try it online!](https://tio.run/##yygtzv6f@6ip8f/DnY32nvnFPpnp////j1YyNDI2MTUwMDYzMjAwMDExUNJBFwKKGCABEBeswszcwhKmGsQ2QOaAVRkYGRgDTTAwNVCKBQA "Husk – Try It Online")
[Answer]
# [Factor](https://factorcode.org/), 42 bytes
```
[ R/ 0+/ [ length >dec ] re-replace-with ]
```
[Try it online!](https://tio.run/##bZDdSsNAEIXv8xRjbzXJmKTVRCj0RilILyxelRLiZrIpJLvrZkoVEXwIn9AXidv4QxDP3XyccxhOVQjWtr9fL1c3GViS9GSgo8c9KUEdtAXXgSlsRxaMJeZnY3eK4QqWqwykbipvcbtcrDOYlyRA7dsHsvOOnUkCnMD1UA8YpCl8vL27ZoKa2XRZGJZadEE1GIQuKdBWhkIrJsXhQdvSz3PJee56z0ZvBDW3jffigdPkPIqTKWI8ixAxSXDyL/6mONIPGpyzi8t0nDze@Bf8JjDC2LXi1Fle@w3chYCnIWygISW5/hpi66b0LZmmEOQfdg5v@7YwEPSf "Factor – Try It Online")
[Answer]
# [Zsh](https://zsh.sourceforge.io/) `--extendedglob`, 24 bytes
```
<<<${1//(#m)0##/$#MATCH}
```
[Try it Online!](https://tio.run/##qyrO@F@cWpJfUKKQWlGSmpeSmpKek5/ElaahWf3fxsZGpdpQX19DOVfTQFlZX0XZ1zHE2aP2fy0XV5qCoZGxiamBgbGZkYGBgYmJAaYQUMQACYC4YBVm5haWMNUgtgEyB6zKwMjAGGiCganBfwA)
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 11 bytes
```
ḅ{ị0&lṫ|}ᵐc
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//@GO1uqHu7sN1HIe7lxdU/tw64Tk//@VDI2MTUwNDIzNjAwMDExMDOBA6X8EAA "Brachylog – Try It Online")
### Explanation
I was hoping for some automatic number -> string conversion, but no dice.
```
ḅ{ị0&lṫ|}ᵐc
ḅ            Break the input string into blocks of identical characters
 {      }ᵐ   Map this predicate to each block:
  ị            Convert to integer
   0           Assert that the result is zero
    &l         If so, get the length of the block
      ṫ        and convert to string
       |       If that failed (because the number wasn't zero), return the block unchanged
          c  Concatenate the results together into a single string
```
[Answer]
# Java, 88 bytes
```
s->java.util.regex.Pattern.compile("0+").matcher(s).replaceAll(r->r.group().length()+"")
```
[Try it online!](https://tio.run/##fY7BTsMwDIbP9CminBJNjbK141KoxAMgkCZOiEPI0i4lTSLHnaimPXsJbBLigm/2/9n@BnVU5bD/WOwYAyAZci8mtE50k9dogxcvXsH8FA0oDNAUcXp3VhPtVErkUVlPTgXJlVBhnv@h73YI1vct6e6XVLa/x8H05lM8K0QDXugwRusMo3JFuRgV6oMBlnjGolPaPDjHoGxB9BCmyLhwxvd4YHxFKV@an/dXravFMdg9GbMcuxi8vhEFfeKn4mY3JzSjCBOKmCN0nnVCxehmRtebqt5KWd1upJR1LSnnzf8bci03ssqw3F7ob5dzcV6@AA)
[Answer]
# [><>](https://esolangs.org/wiki/Fish), ~~23~~ 18 bytes
```
\&l:?n&o]
\i:'0'-?
```
[Try it online!](https://tio.run/##S8sszvj/P0Ytx8o@Ty0/lism00rdQF3X/v9/QyNjE1MDA2MzIwMDAxMTAwA "><> – Try It Online")
[Answer]
# Java 19, 156 ~~161~~ ~~162~~ bytes
```
interface A{static void main(String[] a){var i=0;var s="";for(var c:a[0].toCharArray())if(c==48)i++;else{s+=i>0?i+""+c:c;i=0;}System.out.print(i>0?s+i:s);}}
```
## Without Java's golfing tax, 113 bytes
```
var i=0;var s="";for(var c:a[0].toCharArray())if(c==48)i++;else{s+=i>0?i+""+c:c;i=0;}System.out.print(i>0?s+i:s);
```
[Try it online!](https://tio.run/##LYzRCoIwFEB/Zfi0IclNLcJhIX2Cj@LDZc26pi7mEkT89pXU04Fz4LQ44a69Pb2nwWnboNKsWEaHjhSbDN1YjzTw0lka7lXNUCwTWkY5yI0mL@fR6T4ybycbYxnfrMqwgjpy5vpAW1iLMxeCGq7yPD0JCkOpu1EvJnp9r47TGS4UBkGoMiXktl7/qRt@MQsCIdfVe7@Pk/QAkBxjAEhT@AA "Java (JDK) – Try It Online")
Edit: replaced `'0'` with `48` as suggested in the comments. Thanks!
Edit: String concatentation is shorter than doing `var o=System.out;`
]