Why was 6 afraid of 7?

Retina, 12

Translation of the sed answer:

6*7(6|89)*
7

Try it online


Java, 126 81 66 58 bytes

Thanks to @GamrCorps for providing the lambda version of this code!

Thanks to @user902383 for pointing out an autoboxing trick!

...yup.

It's actually longer than I expected - Java replaces items in strings with replaceAll() once per match, not repeatedly until it stops changing. So I had to use a fancy for loop.

Lambda form:

x->{for(;x!=(x=x.replaceAll("67|76|789","7")););return x;}

Function form:

String s(String x){for(;x!=(x=x.replaceAll("67|76|789","7")););return x;}

Testable Ungolfed Code:

class B{
    public static void main(String[]a){
        System.out.print(new B().s(a[0]));
    }
    String s(String x){for(;x!=(x=x.replaceAll("67|76|789","7")););return x;}
}

Javascript ES6, 29 bytes

s=>s.replace(/6*7(89|6)*/g,7)

Test:

f=s=>s.replace(/6*7(89|6)*/g,7)
;`987 -> 987
6 7 -> 6 7
676 -> 7
7896789 -> 77
7689 -> 7
abcd -> abcd`
.split`\n`.every(t=>(t=t.split` -> `)&&f(t[0])==t[1])