Filter by regex¤
Description¤
The Filter by regex plugin keeps or drops values based on a regular expression. By default, a value is kept only if it matches the regex in full; setting contains relaxes that to keep any value the regex matches anywhere within. Setting negate inverts whichever of those two decisions is in effect.
Notes on regular expressions¤
Attention: regex metacharacters in the pattern have to be escaped to be matched literally, e.g. a literal dot needs \., not ., which otherwise means “any character.”
A pattern that can match an empty string, such as a*, matches every value under contains, since an empty match always “occurs somewhere” in any string.
A regex that fails to compile throws a PatternSyntaxException rather than silently doing nothing.
Attention: This happens during execution. In other words: It’s technically possible to save invalid regular expressions.
Note for advanced users¤
A compilation of the available constructs for building regular expressions is available in the
API of the Java Pattern.
Missing or empty input¤
If no input is connected to this transformer, it throws a ValidationException. If an input is connected but carries no values, the transformer returns nothing for that entity — this is not an error.
Examples¤
Notation: List of values are represented via square brackets. Example: [first, second] represents a list of two values “first” and “second”.
Keeps only values that fully match the regex:
-
Parameters
- regex:
abc
- regex:
-
Input values:
[abc, xabcx, xyz]
-
Returns:
[abc]
Keeps only values consisting of exactly three word characters:
-
Parameters
- regex:
\w\w\w
- regex:
-
Input values:
[abc, ab, abcd, a-x]
-
Returns:
[abc]
Excludes values that fully match the regex, keeping the rest:
-
Parameters
- regex:
abc - negate:
true
- regex:
-
Input values:
[abc, xabcx, xyz]
-
Returns:
[xabcx, xyz]
Keeps values that contain a match anywhere, not just full matches:
-
Parameters
- regex:
abc - contains:
true
- regex:
-
Input values:
[abc, xabcx, xyz]
-
Returns:
[abc, xabcx]
Excludes values that contain a match anywhere, keeping the rest:
-
Parameters
- regex:
abc - negate:
true - contains:
true
- regex:
-
Input values:
[abc, xabcx, xyz]
-
Returns:
[xyz]
A pattern matching zero characters finds a match in any value, so ‘contains’ keeps everything:
-
Parameters
- regex:
a* - contains:
true
- regex:
-
Input values:
[xyz, aaa, ]
-
Returns:
[xyz, aaa, ]
An anchored pattern still only matches at the anchored position, even with ‘contains’ set:
-
Parameters
- regex:
^abc - contains:
true
- regex:
-
Input values:
[abcxyz, xabcx, xyz]
-
Returns:
[abcxyz]
Throws when the regex fails to compile:
-
Parameters
- regex:
(
- regex:
-
Input values:
[abc]
-
Returns:
[] - Throws error:
PatternSyntaxException
A backslash-escaped metacharacter in the regex is matched literally:
-
Parameters
- regex:
a\.b
- regex:
-
Input values:
[a.b, aXb]
-
Returns:
[a.b]
A whitespace-only value matches a whitespace pattern:
-
Parameters
- regex:
\s+
- regex:
-
Input values:
[ , abc]
-
Returns:
[ ]
A Unicode value matches a literal pattern correctly:
-
Parameters
- regex:
café
- regex:
-
Input values:
[café, cafe]
-
Returns:
[café]
Returns nothing when the connected input carries no values:
-
Parameters
- regex:
abc
- regex:
-
Input values:
[]
-
Returns:
[]
Throws when no input is connected:
-
Parameters
- regex:
abc
- regex:
-
Returns:
[] - Throws error:
ValidationException
Parameter¤
Regex¤
The regular expression to test each value against.
- ID:
regex - Datatype:
string - Default Value:
None
Negate¤
If true, keeps values that do not match instead of values that do.
- ID:
negate - Datatype:
boolean - Default Value:
false
Contains¤
If true, the pattern only needs to occur somewhere in the value.
- ID:
contains - Datatype:
boolean - Default Value:
false
Advanced Parameter¤
None
Related Plugins¤
- regexSelect — Filter by regex keeps or drops values from the input sequence based on regex matching. Regex selection keeps the checked value out of the output and instead returns a pattern-list-shaped result filled with the provided output value where a pattern matches.
- validateRegex — Validate regex throws on the first non-matching value, failing the whole operation. Filter by regex just drops it and keeps the rest.
- regexReplace — Filter by regex is a structural filter: it never changes a value’s content, only whether that value appears in the output. Regex replace works the other way: it changes what’s inside each value, but every value that goes in still comes out.
- regexExtract — Regex extract never returns the original value — only part of the match itself, a substring or a capturing group. By contrast, Filter by regex returns only the original value, unmodified, or nothing at all.
- ifMatchesRegex — If matches regex checks one sequence for a match, then returns one of two candidate sequences, completely unchanged. Each value in a single sequence is tested on its own under Filter by regex, kept or dropped to build the output.
- filterByLength — Filter by length only checks length, bounded by a minimum and a maximum. Length is irrelevant to Filter by regex; only the pattern matters.
- removeValues — Remove values checks each value against a fixed, comma-separated blacklist — an exact, case-insensitive match, nothing computed. Filter by regex checks each value against a regular expression instead, which can be a single word or a broad, open-ended pattern.