Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    The regex used here: /^(.*?)\1+$/
    basically means : match a string that starts with any characters (that should be repeated as few times as possible) and put that inside of a group. This group can be repeated 1 or more times until the string ends.

    I assume you got confused by the '*?' the asterisk means 0 or more times and the following '?' makes this expression lazy - means match as few characters that follow the pattern as possible.

    the '\1' refers to the pattern of the matched group, which can be repeated 1 or more times.

    This way he matches the shortest pattern that is repeated through the entirety of the string. A pretty smart way of solving this exercise.

  • Custom User Avatar

    from the description:

    Messages are composed of only letters and digits

  • Default User Avatar

    Really nice solution, but you should probably change the pattern you catch from "(\d*)(\D*)" to "(\d*)([a-zA-z]*)"
    as now you catch every non digit character including spaces, tabs, special chars, instead of just letters like the question required.

    for example is_a_valid_message('2^!') will return True instead of False in your case.