Validate regex¤
Description¤
The validateRegex
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
.
Relation to other plugins¤
Additionally to the validateRegex
plugin, there are related plugins such as ifMatchesRegex
, regexReplace
and
regexExtract
.
The distinctive feature of each of these plugins lies in what happens whenever the regular expression
matches the input value(s): the validateRegex
plugin is used for validating the input, ifMatchesRegex
is useful
for conditionally distinguishing which input to take, regexReplace
replaces all occurrences, and regexExtract
extracts them.
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*
- regex:
-
Input values:
[TestValue123]
-
Returns:
[TestValue123]
Example 2:
-
Parameters
- regex:
[a-d]*
- regex:
-
Input values:
[abcd]
-
Returns:
[abcd]
Example 3:
-
Parameters
- regex:
Prefix \w\w\w
- regex:
-
Input values:
[Prefix abc]
-
Returns:
[Prefix abc]
Example 4:
-
Parameters
- regex:
\w*
- regex:
-
Input values:
[(TestValue123)]
-
Returns:
[]
- Throws error:
ValidationException
Example 5:
-
Parameters
- regex:
[a-d]*
- regex:
-
Input values:
[abcde]
-
Returns:
[]
- Throws error:
ValidationException
Example 6:
-
Parameters
- regex:
Prefix \w\w\w
- regex:
-
Input values:
[Prefixabc]
-
Returns:
[]
- Throws error:
ValidationException
Parameter¤
Regex¤
regular expression
- ID:
regex
- Datatype:
string
- Default Value:
\w*
Advanced Parameter¤
None