Hi, given a string as input, remove any salutations found at the start of the string.

The program which performs the most correct substitutions in under 50 bytes wins.


Hey, a salutation is defined as one of the following words:

  • hi
  • hey
  • hello
  • dear
  • greetings
  • hai
  • guys
  • hii
  • howdy
  • hiya
  • hay
  • heya
  • hola
  • hihi
  • salutations

The first letter may be capitalised.

There will always be a comma and/or a single space following the salutation which must also be removed. The comma and the space may be in any order (,<space> or <space>,) and both should be removed.

The greeting and the following word will only ever be separated by a comma and/or single space.

You must then capitalise the first letter of the word which would have followed the salutation. Even if no replacement has taken place, you should still capitalise the first word of the output.

Capitalisation only applies to lowercase alphabetical characters (abcdefghijklmnopqrstuvwxyz). You should leave any other character as it was.

The salutation will always be at the start of the string. You should not replace a salutation which is not at the start.

There may not always be a salutation.

Your code must be under 50 bytes.


Input > Output

Salutations, what's going on? > What's going on?
hello i have quetions how does juice an avocado > I have quetions how does juice an avocado
How d'you do > How d'you do
Hey,You! > You!
hola cows eat hay > Cows eat hay
hey Hi there! > Hi there!
hihi ,guys > Guys

Test battery

Hola, there are 1000 different inputs in total:

A Bash command to retrieve both the above is

wget https://raw.githubusercontent.com/beta-decay/Remove-Substitutions-Battery/master/{inputs,replaced}.txt


Howdy, the program with the most correct substitutions from the 1000 inputs above wins.

You must put the percentage of the inputs your program handles correctly in your header like so:

# Language Name, percentage%

I'm not completely sure why Jeff made this a thing, but it makes a nice challenge nevertheless.

  • 3
    \$\begingroup\$ s=>System.Text.RegularExpressions.Regex.Replace(); 50 bytes before even a pattern is specified, that's C# out then. (With a regex approach of course) \$\endgroup\$ Commented May 30, 2017 at 12:01
  • 1
    \$\begingroup\$ Python is also out (with regex) :( \$\endgroup\$ Commented May 30, 2017 at 12:50
  • \$\begingroup\$ You can always return the given input for a score of 31.3%. \$\endgroup\$
    – Ian Miller
    Commented May 30, 2017 at 15:57
  • \$\begingroup\$ Urge to edit out the salutation at the beginning of the challenge rising. ;) \$\endgroup\$ Commented May 30, 2017 at 17:02
  • 2
    \$\begingroup\$ Fun anecdote: I originally started my first post on PPCG with "Hello, world! :)" but noticed as soon as I posted it that SE removed the entirety of that line except the ":)". I was of course mortified that I had done something wrong and immediately removed the smiley as well. Not a trace was left in the revision history, and to this day you and I are the only ones who know about it... \$\endgroup\$ Commented May 30, 2017 at 17:03

4 Answers 4


Retina, 68% 72.8% (old) 74.8% 77.5% (new test battery)

i`^h(a[iy]|eya?|i(h?i|ya|)|ello)[ ,]+


Try it online! Edit: Gained 4.8% (old) 2.7% (new) coverage with help from @MartinEnder's tips.

  • 1
    \$\begingroup\$ I think you can do [ ,]+ to squeeze out a few more bytes. You can also extract the h from the alternation. \$\endgroup\$ Commented May 30, 2017 at 11:36
  • \$\begingroup\$ not sure but i`^h(a[iy]|eya?|i(h?i?|ya))[ ,]+ might work meaning you have 8 bytes to spare \$\endgroup\$
    – ASCII-only
    Commented May 30, 2017 at 11:40
  • \$\begingroup\$ @ASCII-only h?i? saves nothing over h?i| and it would match hih (although I don't know whether that's even in the test cases). \$\endgroup\$ Commented May 30, 2017 at 11:41
  • \$\begingroup\$ Actually, it does save a byte if you do ih?i?|iya. \$\endgroup\$ Commented May 30, 2017 at 11:42
  • \$\begingroup\$ Maybe i`^h(a[iy]|eya?|ih?i|iya|ola|ello)[ ,]+ then \$\endgroup\$
    – ASCII-only
    Commented May 30, 2017 at 11:44

GNU sed, 78% 100%


(49 bytes)

The test battery is quite limited: we can count which words appear first on each line:

$ sed -e 's/[ ,].*//' inputs.txt | sort | uniq -ic
 40 aight
 33 alright
 33 dear
 33 g'd
 41 good
 36 greetings
 35 guys
 31 hai
 33 hay
 27 hello
 33 hey
 37 heya
 43 hi
 34 hihi
 29 hii
 35 hiya
 45 hola
 79 how
 37 howdy
 33 kowabunga
 39 salutations
 32 speak
 34 sweet
 40 talk
 36 wassup
 34 what's
 38 yo

The salutations to be removed begin with d, g, h or s (or uppercase versions thereof); the non-salutations beginning with those letters are

 33 g'd
 41 good
 79 how
 32 speak
 34 sweet

Ignoring lines where they appear alone, that's 220 false-positives. So let's just remove initial words beginning with any of those four letters.

When we see an initial word beginning with any of those (/ ^[dghs]\w*), case-insensitively (/i), and followed by at least one non-word character (\W\+), then replace with an empty string. Then, replace the first character with its uppercase equivalent (s/./\U&/).

That gives us


We can now refine this a bit:

  • The largest set of false-positives is how, so we make the substitution conditional by prefixing with a negative test:

  • We can also filter on the second letter, to eliminate g'd, speak and sweet:

  • That leaves only good as a false positive. We can adjust the prefix test to eliminate words ending in either w or d:



$ diff -u <(./123478.sed inputs.txt) replaced.txt | grep ^- | wc -l

PHP, 60.6%

50 Bytes


Try it online!

PHP, 59.4%

49 Bytes

<?=ucfirst(preg_replace("#^h\w+,? #i","",$argn));

Try it online!

PHP, 58.4%

50 Bytes


Try it online!

  • 1
    \$\begingroup\$ 60.1%: #^[gh]\w+.# \$\endgroup\$
    – manatwork
    Commented May 30, 2017 at 12:56
  • \$\begingroup\$ Hey, I've changed to a new test battery, can you update your answer with your new score? Thanks \$\endgroup\$
    – Beta Decay
    Commented May 30, 2017 at 18:13
  • \$\begingroup\$ @BetaDecay is updated \$\endgroup\$ Commented May 30, 2017 at 18:29

Vim, 55.4% 44.4%



df,    Delete until and including the first comma
<<     Remove leading spaces
vgU    Uppercase first letter
  • \$\begingroup\$ Hey, I've changed to a new test battery, can you update your answer with your new score? Thanks \$\endgroup\$
    – Beta Decay
    Commented May 30, 2017 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.