9
Koronkorko is the Finnish word for compound interest. We don't want compound interest in our strings, so let's find the shortest possible regular expression to exclude it.
Given a string consisting only of the uppercase alphabetic characters A-Z, determine the shortest possible regular expression that matches the string if it does not contain the substring KORONKORKO. Any string that contains KORONKORKO as a substring should not be matched by the regex.
Only the characters A-Z, [, ], -, ^, , ?, *, +, |, (, and ) should be used in the expression.
I think this can be done with 118 characters in the expression. Can you make it shorter?
Note: This challenge is from Ohjelmointiputka (in Finnish).
If
!was an allowed character, you could've done^((?!KORONKORO).)*$for 19 bytes. – Mama Fun Roll – 2016-05-12T23:00:05.8173@MamaFunRoll I think that's why
!isn't allow. – Alex A. – 2016-05-12T23:55:41.673I had the fun of trying to work my way around the Finnish site, and I believe what you're looking for are theoretical regex expressions which match/reject the input string. For example, the site only seems to allow the use of
-and^inside character classes (so^can't be used as an anchor), and a match is only counted if the whole string is matched by the regex (i.e. an implicit surrounding^$, as opposed to normal "regexes" which count a string as matching if any part of it matches the regex) – Sp3000 – 2016-05-13T11:15:22.277As such I've deleted my PCRE answer which, while it should work even in PHP, is almost definitely unintended in this case. – Sp3000 – 2016-05-13T11:16:33.017
I forgot to say that the site checks the if the expression is valid by PHP's ereg function. It was said in discussion in http://www.ohjelmointiputka.net/keskustelu/18785-putkaposti-29-k%C3%A4%C3%A4nteislauseke/sivu-1
– guest – 2016-05-13T11:24:11.097