Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 1.14 KB

regex.org

File metadata and controls

48 lines (32 loc) · 1.14 KB

#+title moo regex

Overview

moo schema validation uses JSON Schema compatible regular expressions.

Testing

The moo regex command gives CLI access to testing regular expressions against strings.

Immediate

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'

File based

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'