# Java 10, <s>228</s> <s>227</s> <s>224</s> 182 bytes <!-- language-all: lang-java --> s->{var x="$1$1";int l=s.length();return l>6?s:l>5?s+s.charAt(5):l<2?"#000000":s.replaceAll(l>4?"(.)(.)(.)(.)$":l==3?"([^#]{2})":"([^#])",l>4?"$1$4$2$4$3$4":l>3?x:l>2?x+"$1":x+x+x);} [Try it online.](https://tio.run/##jZJNbsIwEIX3nGJksohFicgvkDSJOEC76RJRyQkGQo1BsUGpUM5OhzTqsrHHtuzxp9G8Jx/ZjU2P269HKZhS8MYqeR8BVFLzesdKDu/PK8CHriu5h9LuD4ommG9x4VSa6aqEd5CQwkNNs/uN1dCkxHItlyRYDESqHMHlXh9smtRcX2sJIotyFYsszNVEOeWB1StthzQWr15OxrNukFg5Nb8IbGUlhC2yICe2Q/@mRWKRpj4m15/jzd1rKYl/z5S8dDT2EFgeLt8KEM78vMHdy5sJPpG4mWDQpH089VyuhUAhvZ7budrCCR3pRa83wGhvx7fS/OScr9q54JMW0pZOaZMxoZ0x/xCzYSQYRnbDCHMNmjGos1wOMy5bDEOe5xsI2xm05Hq@gY3beTQfpoqiCA3MZEVRGvjZ/dlBzJ9HPjfCAm5mRxBGBt4untFz7ah9/AA) **Explanation:** s->{ // Method with String as both parameter and return-type var x="$1$1"; // Create a temp String to repeat a match int l=s.length(); // Length of the String return l>6? // If the length is 7: s // Return the input-String as is :l>5? // Else-if the length is 6: s+s.charAt(5) // Return the input-String with the last character repeated :l<2? // Else-if the length is 1: "#000000"; // Simply return the literal String #000000 : // Else (the length is 2, 3, 4, or 5): s.replaceAll( // Return the input-String after a regex replace: // With as match: l>4? // If the length is 5: "(.)(.)(.)(.)$", // Use a match for pattern #(A)(B)(C)(D) :l==3? // Else-if the length is 3: "([^#]{2})" // Use a match for pattern #(AB) : // Else (the length is 2 or 4): "([^#])", // Use a match for pattern #(A) or #(A)(B)(C) // And as replacement: l>4? // If the length is 5: "$1$4$2$4$3$4" // Change #ABCD to #ADBDCD :l>3? // Else-if the length is 4: x // Change #ABC to #AABBCC :l>2? // Else-if the length is 3: x+"$1" // Change #AB to #ABABAB : // Else (the length is 2): x+x+x);} // Change #A to #AAAAAA