Ad
  • Custom User Avatar

    Ac10y can't be returned as A11y. "A c10(3 characters) y" = A3y. To get A11y you would have to type "Accessability". No math is being done within the regex. Take any string "234543"(243) "hello"(h3o) "234fvj9"(259) and you will get the first and last chars and the number of chars in between. If Ac10y didn't return A3y the test would fail.

    To put it simply the regex says (\w)= give me first character. (\w+{2}) = give me exactly 2 characters multiple times (this should actually be (\w\w+) or (\w{2,}) to guarantee 2 or more letters in between) and the last (\w) = give me the final character(if this wasn't used, the final character would be matched in the second group, this pulls the final character from it.

    Groupings are selfish. They take as much as they can and only leave enough for the next groupings. Take "accessability" and do (\w+)(\w+)(\w+) this will split the word up into three parts, but it won't be even. the first group will take all 11 chars and the next two groups will each get one letter. "accessibili" "t" "y". So it's important to force which groups will be selfish. (\w)(\w+)(\w) (this grouping doesn't work for the test because it would match 3 letter words) which is why we came up with (\w)(\w\w+)(\w)

    Sorry so long.

  • Default User Avatar

    Can't see how this works either, because the regexp takes integers occuring within the string as characters and not as integers already representing the length of a character sequence. Correct me if I'm wrong but at least that's my interpretation of "Ac10y" as input having to be returned as "A11y" (10 + c = 10 + 1 = 11) within the given test, the solution presented here returns A3y by the way (how could it pass the test?).