code: def validate_regexp(ctx, param, value):
      
      if value:
          try:
              value = re.compile(value)
          except ValueError:
              raise click.BadParameter('invalid regular expression.')
      return value
docs: Validate and compile regular expression.