Professor Schwartzman's Acme Canine Decoder 2000
Retina, 24 18 17 16 bytes
1 byte saved based on an idea in MT0's answer.
\wf?k?
y
\byy
He
Try it online!
Explanation
\wf?k?
y
This simply turns all letters into y
, but if they are followed by an f
or k
we immediately replace that as well. By removing f
and k
we "normalise" the lengths of the words so that they now all have two more y
s than they need.
\byy
He
This turns the first two y
of every word into He
, completing the transformation.
Perl, 51 41 39 bytes
s/(G.|[BW]..)(\w+)/He."y"x length$2/ge
Usage
perl -pE 's/(G.|[BW]..)(\w+)/He."y"x length$2/ge'
Input
Bark. Bark! Bark!!
Baaaaaark?
Grrrrrrrr...
?...!
Wooof Woof? Grrrr. Baaaark Grr!
Output
Hey. Hey! Hey!!
Heyyyyyy?
Heyyyyyyy...
?...!
Heyy Hey? Heyyy. Heyyyy Hey!
How it works
Simple regexp substitution using the auto-printing -p
adding 1 byte to the count. /ge
executes the substitution for every pattern, and runs the replacement as code.
An older version used a three-way detection, but Martin Ender noticed that I was not aggressive enough, which saved me 10 bytes.
msh210 informed me that you don't need quotes around the string He
, saving two bytes.
Python, 106 bytes
f=lambda s,a="B,He,Gr,He,Wo,He,a,y,r,y,o,y,f,,yk,".split(","):s if a==[]else f(s.replace(a[0],a[1]),a[2:])
Demo
https://repl.it/C6Rr