import re


def cigarToLen(cigar):
    """
    Calculate sequence length from CIGAR string
    """
    # Split "cigar" on capital letters
    span = re.split('[A-Z]', cigar)
    ops   = re.split('[0-9]+', cigar)
    len = 0
    del(span[-1])
    del(ops[0])
    for i, span in enumerate(span):
      if ops[i] in ["M", "I", "S"]:
        len += int(span)
    return len