import re


def GuessSlugFromTitle(title):
  """Return an automatically generated slug from title. Turn spaces into dashes,
  lowercase everything, limit length."""
  def IsValidChar(c):
    return c.isalnum() or c == '-'

  lower = title.lower()
  slug = lower.replace(' ', '-')
  slug = ''.join([c for c in slug if IsValidChar(c)])
  slug = re.sub("-+", "-", slug)
  return slug