String¶
This module contains a checker for string arguments.
- class argscheck.string.String(*args, **kwargs)¶
Check if
xis a string and optionally, if it matches a particular regex pattern.Regex matching is delegated to the builtin
remodule.- Parameters
pattern – Optional[str] –
xmust match this regex pattern.flags – Optional[re.RegexFlag] – Flags used for modifying the matching behaviour. Only relevant if
patternis provided.method – str – Name of
re.Patternmethod that will be used to matchxagainst the regex pattern. Must be"match","fullmatch"or"search". Only relevant ifpatternis 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")