Skip to main content

Regex

The value shall match the regex /validationRegex/regexFlags.

Parameter table

paramunitrequireddescription
keyyesThe key of the value to check if it matches a regex (key)
validationRegexyesThe regex to match
correctionnoMore details in correction
isPositivenoTrue if the regex is inclusive, False if exclusive
regexFlagsnoAdditional flags appended to the regex

Correction

An optional parameter (correction) is available to specify how an invalid element could be corrected. It's important to note that correction is not mandatory, as there are scenarios where a value that doesn't adhere to the regex may not be correctable. This parameter is in the form of a string, potentially enhanced with captured groups of the regex.

Based on the value of the isPositive parameter (isPositive), the correction is applied differently.

  • In case the regex is positive, we replace the entire value with the correction string since the value is entirely wrong.
  • In case the regex is negative, we replace the matched value with the correction since we want to replace the wrong part of the value.

How to setup

This rule verifies whether the value associated with the provided (key) aligns with the specified regex, along with its associated flag (if one exists) (/validationRegex/regexFlags).

A regex, short for regular expression, is a sequence of characters defining a search pattern within a text. It serves the purpose of identifying matches within a string.

Regex flags are modifiers that can be appended to a regular expression to alter its behavior during pattern matching.These flags provide additional instructions to the regex engine, influencing aspects such as case sensitivity, global matching, and multiline matching. For a detailed syntax and additional information on regular expressions, please refer to this link.

We recommend using Regex101 to build, test and debug regular expressions. Keep in mind that the JavaScript syntax is expected.

If the value of the given (key) doesn't match the regex (/validationRegex/regexFlags), the rule will result in failure.In such instances, the optional correction comes into play, allowing the application of a designated string for correction. For more information, please refer to the correction section.

Creator tips

To get started, you can watch this video on how to use regular expressions.

Additionally, you can use Regex101 to test and debug regular expressions. This provides you with a chance to understand how it works on your submission.

Examples

valuevalidvalidationRegexdescription
Hello World 12!Hello World\s*\d{2}!The value matches the regex.
Hello World!Hello World\s*\d{2}!The value doesn't match the regex.