Skip to content

Test Regular Expression



POST /api/v1/sensitive_data_scanner/regular_test

Overview

Tests a specified regular expression without writing a scanning rule.

Before You Start and Usage Steps

Tests a specified regular expression without writing a scanning rule. Synthetic samples are used. The default engine is Go; saving a rule is still validated with the Go engine. A successful Python test does not mean the expression can be saved. The data scope is the Workspace to which the API Key belongs.

Request Headers

Parameter Type Required Description
DF-API-KEY string Y Access key.
Example: <DF-API-KEY>
How to obtain or provide: Obtain the key required by the current API from API Key Management in the target Workspace.

Body Request Parameters

Parameter Type Required Description
data string Y The sample text to test. Must be non-empty, up to 65536 characters, and is not saved. Only a JSON request body is accepted.
Null allowed: False
Maximum length: 65536
Example: xxx@guance.com
How to obtain or provide: Enter the masking sample to validate, including text that should match and text that should not match.
regularExpression string Y The regular expression to test. Must be non-empty, up to 5000 characters.
Null allowed: False
Maximum length: 5000
Example: [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}
How to obtain or provide: Enter the regular expression corresponding to checkType. To save a scanning rule, choose go for validation.
checkType string Regular expression engine, default is go. python is used only to test Python regular expressions and cannot replace Go validation for saving.
Null allowed: False
Allowed values: ['go', 'python']
Example: go
How to obtain or provide: Choose the engine according to the regular expression syntax. Test expressions intended for rule saving with go.

Additional Parameter Notes

Use the sample text to test the regular expression without changing the rule. Go returns status and match_infos (if any); status=0 means no match and 1 means a match. An invalid Go regular expression returns an error; Python returns matches and status, and status=-1 when the expression is invalid.

Request Example

curl 'https://openapi.guance.com/api/v1/sensitive_data_scanner/regular_test' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"data":"sample without an email","regularExpression":"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"}'

Response

HTTP 200, application/json.

Field Type Description
content.status integer Go: 0 means no match, 1 means a match. Python: -1 indicates an invalid expression.
content.match_infos array Match information from the Go engine, returned when present.
content.matches array Match results from the Python engine; an empty array when the expression is invalid.
{
    "code": 200,
    "content": {
        "status": 0
    },
    "errorCode": "",
    "message": "",
    "success": true,
    "traceId": "TRACE-EXAMPLE"
}

Error Response

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
400 ft.JsonFormatError The top level of the request body is not a JSON object JSON format error Submit a JSON object as the request body.
403 ft.Forbidden Insufficient API permissions, or the current Workspace edition does not support this Access forbidden Confirm the Workspace that owns the key, the permissions, and the Workspace edition.
406 ft.InvalidParameter JSON syntax error, or a missing field, or a field value violates the validation conditions Invalid parameter Check the JSON syntax, fields, types, and value ranges.
400 ft.ErrorRegularExpression The Go engine rejects an invalid regular expression Invalid regular expression Correct it using Go regular expression syntax and retry with a synthetic sample.
406 ft.InvalidParametersValue Python regular expression execution timed out Invalid parameter value Simplify the expression and reduce the test sample, then retry.

Feedback

Is this page helpful?