There is a good solution here to match an IP with a mask eg 192.168.0.1/24
. I add the suggestion from https://regex101.com/ to escape the slash and it looks like this:
((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}\/(?:\d|[12]\d|3[01])$
This definitely seems to work on regex101.
It needs to live inside a json file (jsonschema file) but seems to contain something illegal. Can't work out what it is, have looked at this, this, this and also tried using ujson instead of json (in python) as suggested here, but nothing works.
the following piece of jsonschema which contains that regex:
{
"comment": "ipv4 with a mask",
"data": {
"network": {
}
},
"schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "ipv4 with a mask",
"type": "object",
"properties": {
"subnet": {
"title": "subnet",
"type": "string",
"pattern": "((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}\/(?:\d|[12]\d|3[01])$"
}
}
}
}
...unfortunately won't even parse. Python is saying:
JSONDecodeError: Invalid \escape: line 16 column 33 (char 380)
I have been using the library fastjsonschema to check these things, but can't even parse the json and get that far.
Does anyone know how to fix this, somehow get that piece of regex to function in jsonschema?