[Question]
  [
Given a non-empty string of lowercase ASCII letters `a-z`, output that string with each consecutive “run” of the same letter lengthened by one more copy of that letter.
For example, `dddogg` (**3** `d`’s, **1** `o`, **2** `g`’s) turns into `ddddooggg` (**4** `d`’s, **2** `o`’s, **3** `g`’s).
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"): the shortest answer in bytes wins.
## Test cases
```
aabbcccc -> aaabbbccccc
doorbell -> ddooorrbbeelll
uuuuuuuuuz -> uuuuuuuuuuzz
q -> qq
xyxyxy -> xxyyxxyyxxyy
xxxyyy -> xxxxyyyy
```
  
[Answer]
# [Python 3](https://docs.python.org/3/), 44 bytes
```
for c in input():print(c,end=c[id==c:]);id=c
```
[Try it online!](https://tio.run/nexus/python3#@5@WX6SQrJCZB0QFpSUamlYFRZl5JRrJOql5KbbJ0ZkptrbJVrGa1kBG8v//Kfn5RUmpOTkA "Python 3 – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
.¡€ĆJ
```
Explanation:
```
Example input: "dddogg"
.¡       Split into chunks of consecutive equal elements
         stack: [['ddd', 'o', 'gg']]
  €      For each...
   Ć       Enclose; append the first character to the end of the string
         stack: [['dddd', 'oo', 'ggg']]
    J    Join array elements into one string
         stack: ['ddddooggg']
Implicitly output top element in stack: "ddddooggg"
```
[Try it online](https://tio.run/nexus/05ab1e#@693aOGjpjVH2rz@/y8EAA "05AB1E – TIO Nexus") or as a [test suite](https://tio.run/nexus/05ab1e#qymr/K93aOGjpjVH2rz@6/xPTExKSgYCrpT8/KKk1JwcrlIYqOIq5KqoBEGuioqKyspKAA).
Enclose is a pretty new builtin; it's the first time I've used it. Very convenient ;)
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
γ€ĆJ
```
`.¡` has been replaced by `γ` in the latest update.
[Answer]
# [Retina](https://github.com/m-ender/retina), 11 bytes
```
(.)\1*
$1$&
```
[Try it online!](https://tio.run/nexus/retina#U9VwT/ivoacZY6jFpWKoovb/f2JiUlIyCHCl5OcXJaXmcJXCQBVXIVdFJQhyVVRUVFZWAgA "Retina – TIO Nexus")
Replaces each run of characters with one of the run's characters followed by the run itself.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 bytes
```
r9hMMr8
```
[Test suite](http://pyth.herokuapp.com/?code=r9hMMr8&test_suite=1&test_suite_input=%22aabbcccc%22%0A%22doorbell%22%0A%22uuuuuuuuuz%22%0A%22q%22%0A%22xyxyxy%22%0A%22xxxyyy%22&debug=0).
## How it works
```
r9hMMr8  example input: "xxyx"
     r8  run-length encoding
         [[2, "x"], [1, "y"], [1, "x"]]
  hMM    apply h to each item
         this takes advantage of the overloading
         of h, which adds 1 to numbers and
         takes the first element of arrays;
         since string is array of characters in
         Python, h is invariant on them
         [[3, "x"], [2, "y"], [2, "x"]]
r9       run-length decoding
         xxxyyxx
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 5 bytes
```
Y'QY"
```
[Try it online!](https://tio.run/nexus/matl#@x@pHhip9P@/ekp@flFSak6OOgA "MATL – TIO Nexus")
### Explanation
Consider input `'doorbell'`.
```
Y'    % Implicit input. Run-length encoding
      % STACK: 'dorbel', [1 2 1 1 1 2]
Q     % Increase by 1, element-wise
      % STACK: 'dorbel', [2 3 2 2 2 3]
Y"    % Run-length decoding. Implicit display
      % STACK: 'ddooorrbbeelll'
```
[Answer]
## [Alice](https://github.com/m-ender/alice), 17 bytes
```
/kf.>o./
@i$QowD\
```
[Try it online!](https://tio.run/nexus/alice#@6@fnaZnl6@nz@WQqRKYX@4S8/9/Sn5@UVJqTg4A "Alice – TIO Nexus")
### Explanation
```
/.../
@...\
```
This is a framework for programs which operate entirely in Ordinal mode and are essentially linear (simple loops can be written, and one is used in this program, but it's trickier to work with otherwise branching control flow here). The instruction pointer bounces diagonally up and down through the code from left to right, then gets shifted by one cell by the two mirrors at the end, and the moves back from right to left, executing the cells it skipped on the first iteration. The linearised form (ignoring the mirrors) then basically looks like this:
```
ifQ>w.Doo.$k@
```
Let's go through this:
```
i     Read all input as a string and push it to the stack.
f     Split the string into runs of equal characters and push those
      onto the stack.
Q     Reverse the stack, so that the first run is on top.
>     Ensure that the horizontal component of the IP's movement is east.
      This doesn't do anything now, but we'll need it after each loop
      iteration.
w     Push the current IP address to the return address stack. This marks
      the beginning of the main loop.
  .     Duplicate the current run.
  D     Deduplicate the characters in that run so we just get the character
        the run is made up of.
  o     Output the character.
  o     Output the run.
  .     Duplicate the next run. When we've processed all runs, this will
        duplicate an implicit empty string at the bottom of the stack instead.
  $     If the string is non-empty (i.e. there's another run to process),
        execute the next command otherwise skip it.
k     Pop an address from the return address stack and jump there. Note that
      the return address stack stores no information about the IP's direction,
      so after this, the IP will move northwest from the w. That's the wrong
      direction though, but the > sets the horizontal component of the IP's
      direction to east now, so that the IP passes over the w again and can
      now execute the next iteration in the correct direction.
@     Terminate the program.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
Œg;Q$€
```
[Try it online!](https://tio.run/nexus/jelly#@390Urp1oMqjpjX///9Xr6gEQXUA "Jelly – TIO Nexus")
Only works as a full program (i.e. stringified output).
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
ḅ{t,?}ᵐc
```
[Try it online!](https://tio.run/nexus/brachylog2#@/9wR2t1iY597cOtE5L//1dKyc8vSkrNyVH6HwUA "Brachylog – TIO Nexus")
### Explanation
```
             Example input: "doorbell"
ḅ            Blocks: ["d","oo","r","b","e","ll"]
 {   }ᵐ      Map: ["dd","ooo","rr","bb","ee","lll"]
  t            Tail: "d" | "o" | "r" | "b" | "e" | "l"
   ,?          Prepend to input: "dd" | "ooo" | "rr" | "bb" | "ee" | "lll"
       c     Concatenate: "ddooorrbbeelll"
```
[Answer]
## C, 49 bytes
```
i;f(char*s){for(;putchar(*s);)i=s[i]^s[1]||!s++;}
```
See it [work online](https://ideone.com/u836gV).
[Answer]
# [Python 2](https://docs.python.org/2/), 47 bytes
```
f=lambda s:s and-~(s[0]*2!=s[:2])*s[0]+f(s[1:])
```
[Try it online!](https://tio.run/nexus/python2#NU3BDsIgFLv7Fc93GnMzuiPJ/BHCAUSSJQwczARc5q8jmNgmTdtDm/VoxCyVgEADCKv6TxPYhbfDcQyMDpy0NZ50aa@Uk6ydhwCTBYZCSHkvwA5QOeflw5jqX3@8a1qqxFT5czGmlJDTAzz9ZFfAbYf@BtuO57I9i7UJXXkjJH8B "Python 2 – TIO Nexus")
[Answer]
# C, 53 bytes
```
i;f(char*s){for(;i=*s++;)putchar(i^*s?putchar(i):i);}
```
[Try it online!](https://tio.run/nexus/c-gcc#@59pnaaRnJFYpFWsWZ2WX6RhnWmrVaytba1ZUFoCEtfIjNMqtodzNK0yNa1r/@cmZuZpADVoKKWkpOSnpyuBBAE "C (gcc) – TIO Nexus")
[Answer]
# PHP, 40 Bytes
```
<?=preg_filter('#(.)\1*#',"$1$0",$argn);
```
[Online Version](http://sandbox.onlinephpfunctions.com/code/a48381f186d4e112423529ae856670a0a00fb2f3)
## PHP<7.1, 44 Bytes
Version without Regex
```
for(;a&$c=$argn[$i++];)echo$c[$c==$l].$l=$c;
```
[Online Version](http://sandbox.onlinephpfunctions.com/code/9b3b474ac9ffb310df673f475597ef9bedd918f4)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 bytes
7 bytes of code, +1 for the `-P` flag.
```
ó¥ ®+Zg
```
[Test it online!](http://ethproductions.github.io/japt/?v=1.4.4&code=86UgritaZw==&input=ImFhYmJiY2MiIC1Q)
### Explanation
This uses the `ó` (partition on falsy) built-in that I just added yesterday:
```
ó¥  ®   +Zg
ó== mZ{Z+Zg}
ó==           // Split the input into runs of equal chars.
    mZ{    }  // Replace each item Z in this array with
       Z+Zg   //   Z, concatenated with the first char of Z.
-P            // Join the resulting array back into a string.
              // Implicit: output result of last expression
```
[Answer]
# [Hexagony](https://github.com/m-ender/hexagony), 33 bytes
```
\~..,}/',\<.-/.<@;$>.${;/${/"$.>$
```
### Expanded:
```
   \ ~ . .
  , } / ' ,
 \ < . - / .
< @ ; $ > . $
 { ; / $ { /
  " $ . > $
   . . . .
```
[Try it online!](https://tio.run/nexus/hexagony#@x9Tp6enU6uvrhNjo6err2fjYK1ip6dSba2vUq2vpKJnp/L/f0p@flFSak4OAA "Hexagony – TIO Nexus")
The pseudo-code is more or less:
```
char = readchar()
while (char > 0)
    print(char)
    run_char = char
    do
        print(char)
        char = readchar()
    while (run_char == char)
```
[Answer]
# JavaScript (ES6), ~~33~~ 30 bytes
```
s=>s.replace(/(.)\1*/g,"$1$&")
```
---
## Try It
```
f=
s=>s.replace(/(.)\1*/g,"$1$&")
i.addEventListener("input",_=>o.innerText=f(i.value))
console.log(f("aabbcccc")) // aaabbbccccc
console.log(f("doorbell")) // ddooorrbbeelll
console.log(f("uuuuuuuuuz")) // uuuuuuuuuuzz
console.log(f("q")) // qq
console.log(f("xyxyxy")) // xxyyxxyyxxyy
console.log(f("xxxyyy")) // xxxxyyyy
```
```
<input id=i><pre id=o>
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
n2\×ż
```
[Try it online!](https://tio.run/nexus/jelly#@59nFHN4@tE9////V0/Jzy9KSs3JUQcA "Jelly – TIO Nexus")
### How it works
```
n2\×ż  Main link. Argument: s (string)
n2\    Reduce all overlapping slices of length two by non-equal.
       For input "doorbell", this returns [1, 0, 1, 1, 1, 1, 0].
   ×   Multiply the characters of s by the Booleans in the resulting array. This is
       essentially a bug, but integer-by-string multiplication works as in Python.
       For input "doorbell", this returns ['d', '', 'o', 'r', 'b', 'e', '', 'l'].
       Note that the last character is always left unchanged, as the Boolean array
       has one fewer element than s.
    ż  Zip the result with s, yielding an array of pairs.
       For input "doorbell", this returns [['d', 'd'], [[], 'o'], ['o', 'o'],
           ['r', 'r'], ['b', 'b'], ['e', 'e'], [[], 'l'], ['l', 'l']].
       (implicit) Print the flattened result.
```
[Answer]
# [brainfuck](https://github.com/TryItOnline/tio-transpilers), 23 bytes
```
,[.[->->+<<]>[[-]>.<],]
```
[Try it online!](https://tio.run/nexus/brainfuck#@68TrReta6drp21jE2sXHa0ba6dnE6sT@/9/YmJSUjIIcKXk5xclpebkcJXCQBVXIVdFJQhyVVRUVFZWAgA "brainfuck – TIO Nexus")
### Explanation
```
,            read the first input character
 [           main loop to be run for each input character
 .           output the character once
 [->->+<<]   subtract from previous character (initially 0), and create a copy of this character
 >[          if different from previous character:
   [-]       zero out cell used for difference (so this doesn't loop)
   >.<       output character again from copy
 ]
 ,           read another input character
]
```
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2) `J`, 3 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
ġ€ẹ
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSVDNCVBMSVFMiU4MiVBQyVFMSVCQSVCOSZmb290ZXI9JmlucHV0PSUyMmFhYmJjY2NjJTIyJTIwLSUzRSUyMCUyMmFhYWJiYmNjY2NjJTIyJTBBJTIyZG9vcmJlbGwlMjIlMjAtJTNFJTIwJTIyZGRvb29ycmJiZWVsbGwlMjIlMEElMjJ1dXV1dXV1dXV6JTIyJTIwLSUzRSUyMCUyMnV1dXV1dXV1dXV6eiUyMiUwQSUyMnElMjIlMjAtJTNFJTIwJTIycXElMjIlMEElMjJ4eXh5eHklMjIlMjAtJTNFJTIwJTIyeHh5eXh4eXl4eHl5JTIyJTBBJTIyeHh4eXl5JTIyJTIwLSUzRSUyMCUyMnh4eHh5eXl5JTIyJmZsYWdzPUNKZQ==)
#### Explanation
```
ġ€ẹ  # Implicit input
ġ    # Group consecutive
 €   # Single function map:
  ẹ  #  Enclose (append
     #  first character)
     # Join into a string
     # Implicit output
```
[Answer]
# [Perl 6](https://perl6.org), 18 bytes
```
{S:g/)>(.)$0*/$0/}
```
[Try it](https://tio.run/nexus/perl6#RU5LbsMgEN3PKWYRNZA6JqsuasXqHdqlN@ZTyxLxD6ggUU7WXS/mAo3VGTF6n5knnFH49VKKCi4Bn8QoFZ7X2/trx2hNSro7HdjuxO5rdN@sMhbPqPtBGUJ/vksz6d4Sho054P5Y7zNgtAIXUz/idgWTbgd8zqcVfI7LI@VYI8GmHyZnC2yUn5SwSiLFGyD2BtNHSLZpgZtdYFbgvkopx65LKTLBiDtoW85FrKS2iWQmINoLV1r/bY@RLZyrKGhwW12T6f7pFeakzDP4kDoR70PYHvg0H3KG4Rc "Perl 6 – TIO Nexus")
## Expanded:
```
{   # bare block lambda with implicit parameter ｢$_｣
  S        # replace and return
  :global  # all occurrences
  /
    )>     # don't actually remove anything after this
    (.)    # match a character
    $0*    # followed by any number of the same character
  /$0/     # replace with the character (before the match)
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
.¡DÔ‚ø˜J
```
[Try it online!](https://tio.run/nexus/05ab1e#@693aKHL4SmPGmYd3nF6jtf//xWVIAgA "05AB1E – TIO Nexus")
Explanation:
```
.¡DÔ‚ø˜J
.¡       Split equal runs of input
  D      Duplicate
   Ô     Take connected-uniquified
    ‚    Pair connected-uniquified equal runs with original equal runs
     ø   Zip
      ˜  Deep-flatten (i.e. normal flattening)
       J Join elements together
```
[Answer]
## Haskell, 36 bytes
```
f(a:b:c)=a:[a|a/=b]++f(b:c)
f x=x++x
```
Usage example: `f "aab"` -> `"aaabb"`. [Try it online!](https://tio.run/nexus/haskell#@5@mkWiVZJWsaZtoFZ1Yk6hvmxSrrZ2mARLiSlOosK3Q1q74n5uYmadgq1BQlJlXoqCikJtYoJCmEK2UmJiUlAwESjpKKfn5RUmpOTlAZikMVAE5hUBcUQmCSrH/AQ "Haskell – TIO Nexus")
When the string has at least two chars, bind `a` to the first char, `b` to he second and `c` to the rest of the string. The output is `a` followed by `a` if `a` is not equal to `b` followed by a recursive call with `b:c`. If there's only one char, the result is two times this char. 
[Answer]
## CJam, 10 bytes
```
le`1af.+e~
```
[Try it online!](https://tio.run/nexus/cjam#@5@TmmCYmKannVr3/z8A "CJam – TIO Nexus")
Explanation:
```
e# Input: doorbell
l   e# Read line:              | "doorbell"
e`  e# Run-length encode:      | [[1 'd] [2 'o] [1 'r] [1 'b] [1 'e] [2 'l]]
1a  e# Push [1]:               | [[1 'd] [2 'o] [1 'r] [1 'b] [1 'e] [2 'l]] [1]
f.+ e# Vectorized add to each: | [[2 'd] [3 'o] [2 'r] [2 'b] [2 'e] [3 'l]]
e~  e# Run-length decode:      | "ddooorrbbeelll"
e# Implicit output: ddooorrbbeelll
```
[Answer]
# Ruby, 30 bytes
```
->s{s.gsub(/((.)\2*)/){$1+$2}}
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/) with [AGL](https://github.com/abrudz/agl), 11 bytes
```
⊢é⍨2-0,2=/,
```
[Try it online!](https://tio.run/nexus/apl-dyalog#e9Q31c0zQj0tMyfVSl9fP7@gRD8xPUff0d1HL6UyMSc/Xf2/T2peeklGat6jtgmPuhYdXvmod4WRroGOka2@zn@4pHpiYlJSMhCoc8GFUvLzi5JSc3KQhEphoApJsBCJXVEJgsgCFRWVlZXqAA "APL (Dyalog Unicode) – TIO Nexus")
`,` ravel\*
`2=/` pair-wise comparison (shows which characters to leave as-is)
`0,` prepend a zero (indicating that the initial character should be duplicated)
`2-` subtract that from two (gives 2 for the letters which need to be duplicated, and 1 for the rest)
`⊢é⍨` replicate the argument using that (`é` is just the function `/`)
---
\* This is a no-op on strings, but makes scalar characters into strings. Not required, as argument should be a string, but it makes the tests look neater, and we need a no-op function here anyway. To remove this feature, use `⊢` instead of `,`.
[Answer]
## Batch, 140 bytes
```
@set/ps=
@set r=
:g
@if not "%s:~,1%"=="%s:~1,1%" set r=%r%%s:~,1%
@set r=%r%%s:~,1%
@set s=%s:~1%
@if not "%s%"=="" goto g
@echo %r%
```
Takes input on STDIN.
[Answer]
## sed, ~~18~~ 15 bytes (+1 for -r)
```
s/(.)\1*/\1&/g
```
## Original solution
```
s/((.)\2*)/\1\2/g
```
[Answer]
## R, 36 bytes
```
gsub("((.)\\1*)","\\2\\1",scan(,""))
```
[Answer]
## PowerShell, 50 bytes
```
{-join([char[]]$_|%{if($_-ne$p){($p=$_)}$_});rv p}
```
[Try it online!](https://tio.run/nexus/powershell#NYdBCoAgFAWv0uKLCnmC6CQhplZURJpQaObZzRbN8GAellIpXcA1Hoxxaty2kufPXc5R5sPnF96HEPCDqj5HtpplJ52epes4B/GguEwEBNtHsDQSsC0ImkAk2rirsinnFw)
[Answer]
# Mathematica, ~~34~~ 21 bytes
*Thanks to Martin Ender for finding the* right *way to do this in Mathematica, saving 13 bytes!*
```
##&[#,##]&@@@Split@#&
```
Pure function using an array of characters as both input and output formats. `Split` separates a list into its runs of equal characters. `##&[#,##]&` is a function that returns a sequence of arguments: the first argument it's fed, then all of the arguments (so repeating the first one in particular); this is applied (`@@@`) to every sublist of the `Split` list.
[Answer]
# Java, ~~151~~ ~~146~~ 60 bytes
```
String f(String s){return s.replaceAll("((.)\\2*)","$1$2");}
```
* -5 bytes, thanks to @FryAmTheEggman
* -86 bytes, thanks to @KevinCruijssen
**Regex**
```
(         )     group
 (.)            a character
     \\2*       optional repetition
```
**Detailed**
```
import java.util.*;
import java.lang.*;
import java.io.*;
class H
{
    public static String f(String s)
    {
        return s.replaceAll("((.)\\2*)","$1$2");
    }
    public static void main(String[] args)
    {
        f("dddogg");
    }
}
```
]