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).
!
was an allowed character, you could've done^((?!KORONKORO).)*$
for 19 bytes. \$\endgroup\$!
isn't allow. \$\endgroup\$-
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) \$\endgroup\$