Skip to content

Validate regex¤

Description¤

The Validate regex plugin validates whether all values match a given regular expression.

This plugin is a validation transformer plugin. This means that if the regular expression does not match the input value, it will fail with a validation exception.

Notes on regular expressions¤

The most commonly used examples of regular expressions are "\\s*" for representing whitespace characters, [^0-9]* for numbers, and [a-z]* for the usual English characters between a and z. The star (*) represents an arbitrary number of occurrences (zero included), whereas the plus sign (+) indicates a strictly positive number of occurrences (zero excluded).

An uppercase version of the predefined character classes means negation, such as "\\S*" for non-whitespace characters, or "\\D*" for non-digits. Similarly, the hat sign ^ can be used for negating (arbitrary) character classes, such as [^xyz] for any character except x, y or z.

Attention: Slashes in regular expressions have to be escaped, e.g. instead of \s we need to escape it as \\s.

Note for advanced users¤

A compilation of the available constructs for building regular expressions is available in the API of the Java Pattern.

Examples¤

Notation: List of values are represented via square brackets. Example: [first, second] represents a list of two values “first” and “second”.


Example 1:

  • Parameters

    • regex: \w*
  • Input values:

    1. [TestValue123]
  • Returns: [TestValue123]


Example 2:

  • Parameters

    • regex: [a-d]*
  • Input values:

    1. [abcd]
  • Returns: [abcd]


Example 3:

  • Parameters

    • regex: Prefix \w\w\w
  • Input values:

    1. [Prefix abc]
  • Returns: [Prefix abc]


Example 4:

  • Parameters

    • regex: \w*
  • Input values:

    1. [(TestValue123)]
  • Returns: []

  • Throws error: ValidationException

Example 5:

  • Parameters

    • regex: [a-d]*
  • Input values:

    1. [abcde]
  • Returns: []

  • Throws error: ValidationException

Example 6:

  • Parameters

    • regex: Prefix \w\w\w
  • Input values:

    1. [Prefixabc]
  • Returns: []

  • Throws error: ValidationException

Parameter¤

Regex¤

regular expression

  • ID: regex
  • Datatype: string
  • Default Value: \w*

Advanced Parameter¤

None

  • regexReplace — Regex replace rewrites the input string by substituting every match and returns the rewritten value. Validate regex treats the pattern as a full-value check on the resulting string.
  • ifMatchesRegex — A regular expression match plays different roles here. The Validate regex plugin checks each value against the pattern and passes it through only when it fully matches. The If matches regex plugin uses the match to choose which provided branch value is returned.
  • regexSelect — Regex selection turns one checked value and a list of patterns into a result sequence aligned with that list, placing the provided output value wherever a pattern matches. Validate regex keeps the original value and treats the pattern as a full-value check.
  • regexExtract — Regex extract turns the match into output by returning the matched substring or the first capturing group. Validate regex leaves the value unchanged and only lets it through when the full value matches the pattern.

Comments