When configuring uploaders, you may need to standardize or clean input values—especially when data coming from instruments or filenames uses short codes or shorthand notations. For example, you might receive a file where a material type is labeled with a single character, and you want to substitute it with a full name before extracting it as a condition parameter or metadata field.
This can be done via Header Regex Substitution transformations. They allow you to match values using regular expressions (regex) and perform targeted substitutions.
If you’re dealing with multiple possible values (e.g., A, B, C), and want to map each to a specific replacement (e.g., Alpha, Beta, Gamma), a single conditional regex expression can simplify your setup and prevent the need for multiple chained transformations.
What is Conditional Substitution?
Conditional substitution allows you to apply different replacements based on which value appears in the input. Instead of writing separate transformation blocks for each case, you can use a single regex pattern with optional capture groups and substitute values only if a match is found.
This is particularly helpful when:
- You’re extracting from filenames or headers that may vary by input type.
- You want to map short codes or internal labels to clean, standardized terms.
- You want to avoid the overhead of managing multiple overlapping transformation rules.
How It Works
To perform conditional substitution, use:
- Capturing groups in your regex (e.g.,
(A)?(B)?) to match possible values. - The
${n:+replacement}syntax to define what should be substituted if that group matched.
Example
Suppose your input might contain either A or B:
- Regex pattern:
(A)?(B)? - Substitution string:
${1:+Alpha}${2:+Beta}
This would result in:
- Input
A→Alpha - Input
B→Beta - Input
AB→AlphaBeta - Input with no match → empty string
Syntax Explanation
(A)?and(B)?are optional capture groups. They match the value if present.${1:+Alpha}substitutesAlphaonly if the first group (A) matched.${2:+Beta}substitutesBetaonly if the second group (B) matched.
This lets you collapse multiple substitutions into a single transformation, reducing complexity and ensuring that each input is handled in a single evaluation.
Uncountable-Specific Notes
The syntax is commonly used in regex testing tools like regex101.com, but the exact substitution syntax may vary depending on the regex engine used in Uncountable’s uploader system.
If it doesn’t behave as expected:
- Try escaping special characters, or using
\\1,/1, or alternate formats.