import re


def parse_countdown_length(string):
    """Given a countdown length string, return the number of seconds
    to run for.

    Raises a ValueError if the string cannot be parsed.
    """
    match = re.match(
        r'^(?:(?P<hours>[0-9]+)h\s*)?'
        r'(?:(?P<minutes>[0-9]+)m\s*)?'
        r'(?:(?P<seconds>[0-9]+)s)?$',
        string.strip().lower(),
    )
    if not match:
        raise ValueError('Unable to parse countdown length %r' % string)

    seconds = 0
    if match.group('hours'):
        seconds += int(match.group('hours')) * 60 * 60
    if match.group('minutes'):
        seconds += int(match.group('minutes')) * 60
    if match.group('seconds'):
        seconds += int(match.group('seconds'))
    return seconds