import re


def line_contains_var(line,var):
   """
   Check whether a variable specified by "var" is contained within the line
   specified by "line". E.g. var="t2" and line="a=b+t2*t4" should return
   True whereas line="a=b+t21" should return False.
   """
   regular  = var+"[^0-9]"
   pattern  = re.compile(regular)
   longline = line+" "
   result   = pattern.match(longline)
   return (result != None)