import re


def _extract_revision(str_version):
  """Extract revision (4th component) from version number (if any)."""
  # e.g. '1.0.0.0-prerelease'
  pattern = re.compile(r'^(\d+)(\.\d+)(\.\d+)(\.\d+)(.*)')
  match = pattern.match(str_version)
  if not match:
    return str_version, 0

  return (''.join(
      (match.group(1), match.group(2), match.group(3), match.group(5))),
          int(match.group(4)[1:]))