How to use Spotless Data?

Regex Rules

A regex, or a regular expression, is a small programming expression that can be used to check what is present in a text field.

Wikipedia has an excellent overview of regular expressions here: https://en.wikipedia.org/wiki/Regular_expression

There is also a useful regex tester here: https://regex101.com

Spotless fully implements the Python3 implemented regular expression using the syntax:

match = regex.match(word)
    if match:
        if match.group(0) != "":
            return match.group(0)
        else:
            return None
    else:
        return None

This means that any regex that matches in Python can be deployed in Spotless.

Fields specific to regex rules

The custom fields for Spotless regex rules are as follows:

  • regex - the regular expression

 

Example regex rules

 

There are many example regex rules in the API and an example of a valid JSON for a regex rule is shown below:

{
    "id": "positive-integer-validator-regex-rule-c0e8e0ce-e6c4-11e5-9730-9a79f06e9478",
    "name": "Positive integer Validator",
    "is_private": false,
    "fallback_mode": "remove_record",
    "default_value": "",
    "regex": "^[0-9]*$"
}

Creating regex rules

Regex rules can be created using the browseable API here or in code.

Example code to create a regex rule is as follows:

import requests

token = "<YOUR TOKEN GOES HERE>"

# create a regex rule to validate
response = requests.post(
    "https://spotlessdata.com/api/rules/regex_rules/",
    headers={"Authorization": "Token " + token},
    json={
        "name": "my first spotless regex rule",
        "is_private": false,
        "fallback_mode": "remove_record",
        "default_value": "",
        "regex": "^[0-9]*$"
        ]
    }
)

It's fine to create testing regex rules but please be aware that rules that are not used for 90 days will be deleted from the platform.