<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_unit(C, val, unit=None):

 """convert a string measurement to a Unum"""

        md = re.match(r'^(?P<num>[\d\.]+)(?P<unit>.*)$', val)
        if md is not None:
            un = float(md.group('num')) * CSS.units[md.group('unit')]
            if unit is not None:
                return un.asUnit(unit)
            else:
                return un