code: def getobj(txt, last=False):
      
      txt_end = ""
      for startchar, endchar in ["[]", "()"]:
          if txt.endswith(endchar):
              pos = txt.rfind(startchar)
              if pos:
                  txt_end = txt[pos:]
                  txt = txt[:pos]
      tokens = re.split(SYMBOLS, txt)
      token = None
      try:
          while token is None or re.match(SYMBOLS, token):
              token = tokens.pop()
          if token.endswith('.'):
              token = token[:-1]
          if token.startswith('.'):
              # Invalid object name
              return None
          if last:
              #XXX: remove this statement as well as the "last" argument
              token += txt[ txt.rfind(token) + len(token) ]
          token += txt_end
          if token:
              return token
      except IndexError:
          return None
docs: Return the last valid object name in string