#+title moo regex
moo schema validation uses JSON Schema compatible regular expressions.
The moo regex
command gives CLI access to testing regular expressions against strings.
An immediate test can be done like:
$ moo regex '^[a-z]$' a None $ moo regex '^[a-z]$' aa ... jsonschema.exceptions.ValidationError: 'aa' does not match '^[a-z]$' Failed validating 'pattern' in schema: {'pattern': '^[a-z]$', 'type': 'string'} On instance: 'aa'
A Jsonnet file can be used, with optional path into data structure, eg:
$ moo regex -O -R ipv4 schema/re.jsonnet '1.2.3.4' None $ moo regex -O -R ipv4 schema/re.jsonnet '1.2.3.4.5' jsonschema.exceptions.ValidationError: '1.2.3.4.5' does not match '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$' Failed validating 'pattern' in schema: {'pattern': '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$', 'type': 'string'} On instance: '1.2.3.4.5'