import re


def getNumberOf(line, tag):
    """
    Reads the alignment tag, given the text and a tag to search for.

    @type  line: string
    @param line: SAM line
    @type  tag: string
    @param tag: SAM tag. i.e: NM,MD
    @rtype:   int
    @return:  number x behind desired tag tag:i:x
    """

    # gives the number of XX back
    # valid tags: X0,XM (number of missmatches
    m = re.search(tag + ":i:(\d+)", line)
    besthits = m.group(1)
      
    return(besthits)