from typing import Optional
import re


def _extract_job_id(job_name: str) -> Optional[str]:
  """Extracts job id from job name.

  Args:
   job_name: The full job name.

  Returns:
   The job id or None if no match found.
  """
  p = re.compile(
      'projects/(?P<project_id>.*)/locations/(?P<region>.*)/pipelineJobs/(?P<job_id>.*)'
  )
  result = p.search(job_name)
  return result.group('job_id') if result else None