g | x | w | all
Bytes Lang Time Link
079Swift 6240305T003913ZmacOSist
009Vyxal240304T225015Zemanresu
008Japt151227T013250ZETHprodu
014V vim210409T014613ZRazetime
081brainfuck210412T054602ZRezNesX
016K ngn/k210409T155547Zcoltim
035Vim210408T232843Zuser
012Vim210408T235621ZLeo
009Jelly210408T215549Zcaird co
018APL Dyalog Unicode180603T183557ZErik the
020Ruby150711T093845Zmanatwor
007TeaScript151117T045259ZDowngoat
172Oracle SQL 11.2160209T200354ZJeto
037jq 1.5150714T193743Zmanatwor
810π”Όπ•Šπ•„π•šπ•Ÿ151229T223744ZMama Fun
073Emacs Lisp151225T164617ZLord Yuu
039Javascript ES6151216T223634ZQwertiy
nan151217T112212Zalexcat3
047Haskell150712T003616Znimi
036><>151117T144044ZAaron
050bash151117T215444ZF. Hauri
060JavaScript151117T192634ZAmechra
008rs150723T023317Zkirbyfan
138Batch150713T064741Zunclemea
039Julia150715T083753ZGlen O
123Java150710T225000ZStretch
080VisualFoxPro any version150715T153520ZChris
041Julia150711T000542ZAlex A.
084Mumps150714T191734Zzmerch
077Java150712T235939ZOlivia T
047Haskell150711T000523Zlynn
057ECMAScript 6150711T003123ZDowngoat
052R150711T034117ZAlex A.
006Gema150711T102328Zmanatwor
010REGXY150712T161112ZJarmex
015Perl150711T094244Zmanatwor
062Javascript150711T161741ZIsmael M
039JavaScript ES6150711T074845Zedc65
036golflua150711T160636Zmanatwor
064K5150711T160212Zkirbyfan
013CJam150710T221720ZOptimize
013Retina150710T215707Zrandomra
050Python 2150711T090758Zfeersum
053Python 3150711T073913ZSp3000
nanPython 2150711T013058ZKade
052C150710T235248ZBrainSte
011GNU sed150710T232938ZDigital
011Pyth150710T222450Zizzyg
019Pyth150710T215539ZMaltysen

Swift 6, 81 79 bytes

let f={(s:inout _)in while(s+"").contains("^"){s={s.replacing}()(/.\^H/,"",1)}}

Call it like this:

var s = "Horse^H^H^H^H^HCow"
f(&s)
print(s) // "Cow"

Vyxal, 9 bytes

β€›^H/Ζ’Ξ»$αΉͺp

Try it Online! Port of caird coinheringaahing's Jelly answer.

   /      # Split on
β€›^H       # "^H"
    Ζ’Ξ»--- # Reduce by
        p # Prepend to the first item
      $αΉͺ  # The second with its last item removed

Japt, 8 bytes

Ue/.\^H/

Try it online!

How it works

U        // Take the input,
e/.\^H/  // and recursively replace any char followed by "^H" with
         // (nothing, defaults to an empty string).
         // Implicit: output last expression

V (vim), 16 14 bytes

qq:s/.^H
@qq@q

Try it online!

similar to sed, but uses Vim's recursion.

brainfuck, 81 bytes

>,[[>+>+<<-]-[>-<---]>---------[>>+<<[-]]>>-[+<[-]<<<,[-]>>]<[<<+>>-]<,]<[<]>[.>]

Try it online!

K (ngn/k), 23 16 bytes

-7 bytes by rereading question (specifically, "^ will only appear as ^H")

{x_/3#-1+x?"^"}/

Try it online!

Removes one instance of ?^H on each invocation, and is run until convergence (i.e. no more ^'s are present).

Vim, 38 35 bytes

Saved 3 bytes thanks to Leo!

qa:%s/\([^H]\|\^\@<!.\)\^H//g
@aq@a

Try it online!

See Razetime's answer for a shorter and smarter version of this.

qa:%s/\([^H]\|\^\@<!.\)\^H//g
@aq@a

qa                                     Start recording a macro a
  :%s/                                 Substitute in entire file
      \([^H]\|\^\@<!H\)                Regex for the character to be deleted
        [^H]                           A character that isn't H
            \|                         or
                    H                  an H
              \^\@<!                   that doesn't have a ^ before it
                       \^H             All of that followed by ^H
                          //           Replace with empty string
                            g          Global flag so it replaces multiple times
                                       Enter the command
@a                                     Recursively call macro a
  q                                    Stop recording
   @a                                  Run the macro
```

Vim, 12 bytes

qqt^3xh@qq@q

Try it online!

Makes use of the fact that "^ will only appear as ^H".

Explanation

qqt^3xh@qq@q
qq     @qq@q    Define an indefinitely looping recursive macro and immediately call it
  t^            Move to just before the next ^ character in the line
    3x          Delete 3 characters (the one to be deleted, ^, and H)
      h         Move left 1 step (to be in position for the next search)

Jelly, 9 bytes

œṣ⁾^HαΉ–;Β₯/

Try it online!

Not a new approach, but the question was missing a Jelly answer

How it works

œṣ⁾^HαΉ–;Β₯/ - Main link. Takes a string S on the left
  ⁾^H     - Yield "^H"
Ε“αΉ£        - Split on "^H"
       Β₯/ - Reduce by the following:
     αΉ–    -   Remove the last character
      ;   -   And append the right argument

APL (Dyalog Unicode), 18 bytes

'.\^H'βŽ•R''⍠'ML'1⍣≑

Try it online!

Ruby, 27 24 20 bytes

(19 characters code + 1 character command line option.)

$_=$`+$'while/.\^H/

Thanks to:

Sample run:

bash-4.3$ ruby -pe '$_=$`+$'"'"'while/.\^H/' <<< "Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ."
Be nice to this gentleman, he's visiting from corporate HQ.

TeaScript, 7 bytes [Not competing]

Not competing as TeaScript was made after this challenge was posted. This is here as reference.

xW/.\^H

This uses the new TeaScript 3, and recursive replaces to remove the characters

Oracle SQL 11.2, 172 bytes

WITH v(s,i)AS(SELECT:1,INSTR(:1,'^')FROM DUAL UNION ALL SELECT LPAD(s,i-2)||SUBSTR(s,i+2),INSTR(s,'^',1,2)-3 FROM v WHERE i>0AND'^'<>s)SELECT s FROM v WHERE INSTR(s,'^')=0;

Un-golfed

WITH v(s,i) AS                        -- Recursive view, s-> string, i->pos of first ^
(
  SELECT :1,INSTR(:1,'^')             -- Initialisation view 
  FROM   DUAL
  UNION ALL
  SELECT LPAD(s,i-2)||SUBSTR(s,i+2),  -- Remove the ^ at pos i and the characters before and after 
         INSTR(s,'^',1,2)-3           -- Compute the pos of the next ^ (the 2nd of s as before the remove just above)
  FROM   v 
  WHERE  i>0                          -- Exit clause : no more ^
    AND  s<>'^'                       -- Needed to circumvent oracle's cycle detection, without it 123^H45^H^H^H78^H will fail
)
SELECT s FROM v WHERE INSTR(s,'^')=0; -- Keep only the row without any ^

jq 1.5, 41 37 bytes

(34 characters code + 3 characters command line option.)

reduce(./"^H")[]as$t("";.[:-1]+$t)

Sample run:

bash-4.3$ bin/jq -R -r 'reduce(./"^H")[]as$t("";.[:-1]+$t)' <<< "Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ."
Be nice to this gentleman, he's visiting from corporate HQ.

On-line test (Passing -R through URL is not supported – so input passed as JSON string literal. Passing -r through URL is not supported – check Raw Output yourself.)

π”Όπ•Šπ•„π•šπ•Ÿ, 8 chars / 10 bytes (noncompetitive)

Γ―Δ—/.\^H/

Try it here (Firefox only).

Works like all of the other JSGL's.

Emacs Lisp, 45 73 bytes

(lambda(s)(while(string-match".^H"s)(set's(replace-match"" nil nil s)))s)

Searches for the first occurence of anything else and ^H as long as it exists and replaces it with an empty string.

Old, incorrect version

(lambda(s)(replace-regexp-in-string".^H"""s))

Javascript ES6, 41 39 bytes

f=s=>s==(s=s.replace(/.\^H/,""))?s:f(s)

JavaScript, 60 Bytes

I know there is already a JS answer here, but wanted to do it without regexes, because regex is really almost a language by itself. I'm sorry if you feel I shouldn't post this, this is my first post.

X is the string to be operated upon.

while((z=x.indexOf('^D'))>0){x=x.slice(0,z-1)+x.slice(z+2);}

Test

Put this into your browser's address bar.

javascript:x=prompt('Enter the sentence to be erased');while((z=x.indexOf('^D'))>0){x=x.slice(0,z-1)+x.slice(z+2);}alert(x);

I love JS because it will let you do things like saying (z=x.indexOf('^D))>0, and it will both assign z.indexOf('^D'); to x and evaluate z.indexOf('^D') in the condition, which saves me precious bytes in this problem. It's not very useful otherwise, but it's fun!

Haskell, 52 47 bytes

import Data.Lists
foldl1((++).init).splitOn"^H"

Usage example:

> map (foldl1((++).init).splitOn"^H") ["Horse^H^H^H^H^HCow", "123^H45^H^H^H78^H", "Digital Trauma^H^H^H^H^H^H^H^H^H^H^H^H^H^HMaria Tidal Tug^H^H^H^H^H^H^H^H^H^H^H^H^H^H^HDigital Trauma"]
["Cow","17","Digital Trauma"]

How it works:

                  splitOn"^H"     -- split on substring "^H", e.g "Horse^H^H^H^H^HCow" -> ["Horse","","","","","Cow"]
                 .                -- then
foldl1(         )                 -- fold from left by
            init                  --   first dropping the last char from the left argument
       (++).                      --   second concatenating left and right argument

><>, 39 38 36 bytes

There was no ><> answer so I thought I'd add one.

i:0(?v:'^'=?\
     ~   ~~i/
;!?lr<ro

bash, 50 bytes

while [ "$a" != "${a/?^H/}" ];do a=${a/?^H/};done

Sample:

a=$'Horse^H^H^H^H^HCow'
while [ "$a" != "${a/?^H/}" ];do a=${a/?^H/};done
echo $a
Cow

a="Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ."
while [ "$a" != "${a/?^H/}" ];do a=${a/?^H/};done
echo $a
Be nice to this gentleman, he's visiting from corporate HQ.

This could work with real (binaries) backspaces as well:

a=$'Be nice to this fool\b\b\b\bgentleman, he'\'$'s visiting from corporate HQ.'
echo $a.. but:
Be nice to this gentleman, he's visiting from corporate HQ... but:
printf %q\\n "$a"
$'Be nice to this fool\b\b\b\bgentleman, he\'s visiting from corporate HQ.'

while [ "$a" != "${a/?$'\b'/}" ];do a=${a/?$'\b'/};done
printf %q\\n "$a"
Be\ nice\ to\ this\ gentleman\,\ he\'s\ visiting\ from\ corporate\ HQ.

JavaScript, 60 bytes

b=n=>(v=n.search('^H'))>0?b(n.replace(n.slice(v-1,v+2),'')):n

Not as good as edc65's answer, but I wanted to try something that didn't use Regex.

rs, 8 bytes

Technically, this doesn't count, as it depends on a feature I added after this question was posted. However, I think it's pretty neat.

+?1.\^H/

Live demo and test cases.

Batch - 138 bytes

@!! 2>nul||cmd/q/v/c%0 %1&&exit/b
set s=%1&for /F %%a in ('"prompt $H&echo on&for %%b in (1)do rem"')do set D=%%a
echo %s:^H=!D! !D!%

The first line is a way of saving a few bytes over the lengthy @echo off&setLocal enableDelayedExpansion (which turns echo off and enables the delayed expansion of variables, in case you were wondering). I explained it in Tips for Golfing in Batch.

The second line is a neat little trick to save the a backspace control character into a variable. It's pretty hacky, and I can't pretend to take credit for it. It's sort of explained here. Basically uses the prompt command to generate a backspace character and captures it in a variable - in this case !D!.

The final line then performs the simple string manipulation of - replace ^H with !D!<SPACE>!D!.

C:\>bsp.bat "testing^H^H^H test"
"test test"

Unfortunately it breaks with cases like "AAA^HB^H^H" - where it should produce "A", it instead produces "A"B. Which is somewhat confusing. I'll have to look into how Batch string manipulation works in some more depth.

C:\>bsp.bat "AAA^HB^H^H"
"A"B

Thanks to to some helpful people over here - I now realize that I was only saving the backspace character (0x08), and so was only overwriting the characters. It now works with examples like the following:

C:\>bsp.bat "AAA^HB^H^H"
"A"

Julia, 41 39 bytes

s->foldl((t,v)->chop(t)v,split(s,"^H"))

What it's doing is using ^H as a delimiter, and then removing the last character on each string then concatenating the next string before removing the last character again. Unlike the other Julia answer, this is not a recursive function.

Note: I've removed the function name from the definition. Originally, it said f(s)= rather than s->, and you used it as f("AAA^HB^H^H")... but I'm saving two bytes by letting it be "anonymous", and use itself as its name. You use it like this:

(s->foldl((t,v)->chop(t)v,split(s,"^H")))("AAA^HB^H^H")

(you can also assign a variable to it as f=s->foldl((t,v)->chop(t)v,split(s,"^H")), then f("AAA^HB^H^H") will work)

Java - 123 bytes

I personally like the g---1 part the best.

String f(char[] a){String b="";for(int g=-1;++g<a.length;b=(a[g++]=='^'?b.substring(0,b.length()-1):b+a[g---1]));return b;}

expanded (slightly):

  String f(char[] a) {
      String b = "";
      for (int g = -1;
           ++g < a.length;
           b = (a[g++]=='^' 
                ? b.substring(0, b.length() - 1) 
                : b + a[g---1])
      );
      return b;
  }

(Visual)FoxPro any version 80 bytes

PARA t
DO WHILE AT('^H',t)>0
t = STRT(t,SUBS(t,AT('^H',t)-1,3))
ENDDO
RETU t

Repeating string translation to empty by finding ^H and backing up one character.

Julia, 58 42 41 bytes

Saved 16 bytes thanks to manatwork and 1 thanks to Glen O!

f(s)='^'∈s?f(replace(s,r".\^H","",1)):s

This creates a recursive function that accepts a string and returns a string.

This replaces one occurrence of ^H at a time with an empty string while the input contains ^.

Examples:

julia> f("123^H45^H^H^H78^H")
"17"

julia> f("pizza is alright^H^H^H^H^H^Hwesome")
"pizza is awesome"

Mumps, 84 Bytes

R Z S T="",Y=$L(Z,"^H") F I=1:1:Y{S T=T_$P(Z,"^H",I) S:I<Y T=$E(T,1,$L(T)-1)} W !,T

This could probably be made shorter as a function (1 byte I was able to save in quick testing) but I kinda like the one-liner aspect... :-)

The braces come from the Intersystems Cache flavour of Mumps which is what I'm most versed in.

Java, 78 77 bytes

String f(String a){while(!a.equals(a=a.replaceFirst(".\\^H","")));return a;}

Haskell, 47 bytes

h(a,_:_:b)=f$init a++b;h(x,_)=x
f=h.span(/='^')

Defines a function f :: String -> String. How it works:

    f "ab^Hc^Hd"
=== h ("ab", "^Hc^Hd")   (find ^H)
=== f ("a" ++ "c^Hd")    (backspace)
=== f "ac^Hd"            (join)
=== h ("ac", "^Hd")      (find ^H)
=== f ("a", "d")         (backspace)
=== f "ad"               (join)
=== h ("ad", "")         (find ^H)
=== "ad"                 (no ^H: base case)

ECMAScript 6, 57 bytes

s=>{while(~s.indexOf`^H`)s=s.replace(/.\^H/,'');return s}

This is probably golfable, just gotta think of a way probably not

R, 54 52 bytes

f=function(s)ifelse(s==(r=sub(".\\^H","",s)),r,f(r))

Same basic idea as my Julia answer. This creates a recursive function that accepts a string and returns a string. If the input is equal to itself with a single occurrence of ^H removed, return it, otherwise call the function again.

You can try it online!

Gema, 6 bytes

?#\^H=

Sample run:

bash-4.3$ gema -p '?#\^H=' <<< 'pizza is alright^H^H^H^H^H^Hwesome'
pizza is awesome

CW, because the fool vs. gentleman example takes far too long. (Killed after a day. Maybe a glitch in the interpreter? All other examples here are processed in fractions of seconds.) Gema's recursive pattern not seems to be affected by the recursion level, but the amount of non-matching text increases processing time exponentially.

REGXY, 10 bytes

Uses REGXY, a regex substitution based language. Replaces any character followed by ^H with nothing. The second line then executes which is just a pointer to the previous line, repeating the substitution until it fails to match.

/.\^H//
//

This compiles and executes correctly with the sample interpreter in the link above, but the solution is perhaps a bit cheeky as it relies on an assumption in the vagueness of the language specification. The spec states that the first token on each line (before the /) acts as a label, but the assumption is that a null label-pointer will point back to the first command in the file with a null label (or in other words, that 'null' is a valid label). A less cheeky solution would be:

a/.\^H//
b//a

Which amounts to 13 bytes.

Perl, 20 16 15 bytes

(14 characters code + 1 character command line option.)

s/.\^H//&&redo

Sample run:

bash-4.3$ perl -pe 's/.\^H//&&redo' <<< "Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ."
Be nice to this gentleman, he's visiting from corporate HQ.

Javascript, 62 bytes

Not the shortest one, but works fine.

t=prompt();while(t.match(R=/.\^H/))t=t.replace(R,'');alert(t);

This probably can be shortened a lot!

JavaScript (ES6), 39 bytes

f=s=>(t=s.replace(/.\^H/,''))!=s?f(t):t

// TEST

Out=x=>O.innerHTML+=x+'\n'

Test=_=>(Out(I.value + "\n-> " + f(I.value)),I.value='')

;["Horse^H^H^H^H^HCow"
,"Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ."
,"123^H45^H^H^H78^H"
,"Digital Trauma^H^H^H^H^H^H^H^H^H^H^H^H^H^HMaria Tidal Tug^H^H^H^H^H^H^H^H^H^H^H^H^H^H^HDigital Trauma"]
.forEach(t => Out(t + "\n-> " + f(t)))
#I { width:400px }
<pre id=O></pre>
<input id=I><button onclick='Test()'>-></button>

golflua, 36 bytes

\f(s)@o!=s o=s;s=s:g(".^H","",1)$~s$

Sample run:

Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> \f(s)@o!=s o=s;s=s:g(".^H","",1)$~s$
> w(f("Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ."))
Be nice to this gentleman, he's visiting from corporate HQ.

K5, 64 bytes

K isn't really designed for this kind of work...

{[s]$[2>#s;s;`=t:*&{"^H"~2#x_s}'1+!-2+#s;s;,/2#2!|(0,t,3+t)_s]}/

CJam, 14 13 bytes

q"^H"/{W\ts}*

How it works

q                   e# Read the entire input
 "^H"/              e# Split it on occurrences of string "^H"
      {    }*       e# Reduce on the split array
       W\t          e# This is the tricky part. We know that if there are two parts that we
                    e# are reducing on, they must be separated by "^H". Which in turn means
                    e# that from the first part, last characters needs to be deleted
                    e# So we simply put the second part in place of the last character of the
                    e# first part.
          s         e# Doing the above makes it a mixed array of character and string.
                    e# So we convert it to a single string, ready to be served as first part
                    e# in next reduce iteration

UPDATE: 1 byte saved thanks to jimmy23013

Try it online here

Retina, 13 bytes

Retina

+`.\^H(.*)
$1

The two lines should go to their own files but you can run the code as one file with the -s flag.

At each step we delete the first match for .\^H in the string. We repeat this (with the + modifier) until no deletion happens.

Python 2, 50

It's a bit odd having a second lambda in there, but seems to be the best Python so far.

lambda s:reduce(lambda a,b:a[:-1]+b,s.split('^H'))

Python 3, 53 bytes

o=""
for x in input().split("^H"):o=o[:-1]+x
print(o)

But personally I like this wordier version better:

H=input().split("^H")
print(eval("("*~-len(H)+")[:-1]+".join(map(repr,H))))

The interesting thing is that

'B''a''c''k''h''a''n''d''e''d'[:-1][:-1][:-1][:-1][:-1][:-1]

actually works and gives 'Back', so I tried to map ^H -> [:-1] and any other char c -> 'c' then eval, but unfortunately you can't have any strings afterwards without a +, so this fails:

'B''a''c''k''h''a''n''d''e''d'[:-1][:-1][:-1][:-1][:-1][:-1]'s''p''a''c''e''s'

Python 2, 74 + 2 = 76 Bytes

I've tried a few approaches so far, this is the best I've been able to come up with so far.

n=input();o='';c=0
for l in n:d=l=='^';o=[o+l*(1-c),o[:-1]][d];c=d
print o

C, 52 bytes

j;f(char*s){for(j=0;*s=s[j];s[j]==94?s--,j+=3:s++);}

We define a function f that takes a pointer to the string as input. After the function call, that pointer will contain a modified string.

A simple test:

int main(int argc, char** argv) {
    char buf[300] = "Digital Trauma^H^H^H^H^H^H^H^H^H^H^H^H^H^HMaria Tidal Tug^H^H^H^H^H^H^H^H^H^H^H^H^H^H^HDigital Trauma";
    f(buf);
    printf(buf);
    return 0;
}

The above prints:

Digital Trauma

GNU sed, 11 bytes

:;s/.^H//;t

Test output:

$ echo "Horse^H^H^H^H^HCow
Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ.
123^H45^H^H^H78^H
Digital Trauma^H^H^H^H^H^H^H^H^H^H^H^H^H^HMaria Tidal Tug^H^H^H^H^H^H^H^H^H^H^H^H^H^H^HDigital Trauma" | sed ':;s/.^H//;t'
Cow
Be nice to this gentleman, he's visiting from corporate HQ.
17
Digital Trauma
$ 

Pyth, 11 bytes

.U+PbZcz"^H

Demonstration.

.U+PbZcz"^H
               Implicit: z = input()
      cz"^H    z.split("^H")
.U             reduce, with the first element of the list as the initial value.
   Pb          Remove the last character of what we have so far.
  +  Z         And add on the next segment.
               Print implicitly.

Pyth - 19 bytes

Reduce works really, really well with this but it only does one char at a time so I had to spend almost as many chars as the actual algo to do a replace ^H with linebreak. Looking for a better way to do that.

u?+GHnHbPGjbcz"^H"k

Try it online here.