<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse_compound(s, global_compartment=None):
 """Parse a compound specification. If no compartment is specified in the string, the global compartment will be used. """

    m = re.match(r'^\|(.*)\|$', s)
    if m:
        s = m.group(1)

    m = re.match(r'^(.+)\[(\S+)\]$', s)
    if m:
        compound_id = m.group(1)
        compartment = m.group(2)
    else:
        compound_id = s
        compartment = global_compartment

    return Compound(compound_id, compartment=compartment)