String

This module contains a checker for string arguments.

class argscheck.string.String(*args, **kwargs)

Check if x is a string and optionally, if it matches a particular regex pattern.

Regex matching is delegated to the builtin re module.

Parameters
  • patternOptional[str]x must match this regex pattern.

  • flagsOptional[re.RegexFlag] – Flags used for modifying the matching behaviour. Only relevant if pattern is provided.

  • methodstr – Name of re.Pattern method that will be used to match x against the regex pattern. Must be "match", "fullmatch" or "search". Only relevant if pattern is provided.

Example

from argscheck import String

# Check if a string ending with ".exe"
checker = String(".*\.exe$")

checker.check("app.exe")    # Passes, returns "app.exe"
checker.check("script.sh")  # Fails, raises ValueError ("script.sh" does not end with ".exe")