from typing import Pattern
import re


def default_compile_regex(r: str) -> Pattern[str]:
  """Compiles a regex with useful flags, and raises ValueError on failure."""
  try:
    return re.compile(r, re.M)
  except re.error as e:
    raise ValueError('Failed to parse regular expression (%s): %s' % (e, r))