import re


def cleanlines(lines):
  """Remove comments and blank lines from splitlines output."""
  # Clean comments.
  matchRE = re.compile('(.*?)(//|%|#)')
  for i in range(len(lines)):
    line = lines[i]
    match = matchRE.match(line)
    if match is not None:
      lines[i] = match.group(1)
  # Clean blank lines.
  return [x.strip() for x in lines if len(x.strip()) > 0]