Regex
I have a very complicated regex validation that I have embedded in a Workflow Designer form. I need to use that same regex for about 25 different fields across several forms. Rather than re-typing it every time, which makes keeping it up-to-date nearly impossible, is there a way I can store it once and have the forms reference the single stored location?
Thanks...
S Benson
Posted 10 months ago · Edited 10 months ago·Last reply 9 months ago
6 comments
Grant Rollerson
·10 months ago · EditedWhy not store it in a Ref Data Code Set / Code Value? Keep it in an Admin Community and if helpful, include a specific scope (message format).
Sean Pyle
·10 months ago · EditedVery clever!
S Benson
OP10 months ago · EditedI like the idea - thats exactly what I want to do. But I am at a loss as to how to reference it? Making sure I follow... I set up a code set "Colors", and I create code values R (Red), B (Blue), G (Green), etc. What do I write in the form to access my code set? And where?
Grant Rollerson
·10 months ago · Edited@scottbenson LLMs are your friend ;-) below is Copilot with GPT-5 On. You might need to whisper a bit betterer but it'll get there....
Here’s Answer2 for your scenario:
How to Reference a Code Set Value in a Workflow Designer Form
Once you’ve created your Ref Data Code Set (e.g.,
Colors) and added Code Values (e.g.,R,B,G), you can reference them in your form using the Expression Builder or Validation Rule.Steps:
Create the Code Set and Values
Go to Admin → Reference Data → Code Sets.
Create a Code Set called
RegexPatterns(instead ofColorsfor your case).Add a Code Value like:
Code:
ComplexRegexDescription: Your full regex pattern.
Access the Code Value in the Form
In Workflow Designer, open your form.
For the field where you want validation, go to Validation Rule or Expression.
Use the function:
This retrieves the Description of the
ComplexRegexcode value.Apply It in Regex Validation
If the validation rule supports dynamic regex, you can do:
matches(FieldValue, RefData("RegexPatterns", "ComplexRegex"))WhereFieldValueis the field input.Why This Works
RefData(CodeSetName, CodeValue)is the standard function to pull reference data dynamically.This way, you only update the regex in Admin → Reference Data, and all forms using it will automatically stay in sync.
Do you want me to write a full example validation expression for Workflow Designer, showing how to integrate this with
matches()and conditional logic? Or should I also include best practices for managing multiple regex patterns in one Code Set?S Benson
OP10 months ago · Edited@Grant Rollerson I appreciate the help! I'm close, but my tweaks arent solving the problem. ARGHH. Step 1 was not a problem. Step 2 is the problem - I dont see "Validation Rule or Expression". The closest I can find is "Validation Regex", but thats for Step 3. I tried combining 2 and 3 into 3, and that didnt work. I know I'm close, but still cant get it to work. I appreciate all of the help.
Scott
Grant Rollerson
·9 months ago · EditedDid you look here > Create a workflow with dynamic forms
I asked our LLM again ... but you can do the same thing ... just need to keep tweaking & whispering!!!
Below is a comprehensive, end‑to‑end approach to centralize a complex regex in Collibra and reuse it across many Workflow Designer forms—covering where to store it, how to reference it, and how to combine it with all four validation options (Required, Regex, Min/Max Length, and Custom validations
{{…}}). I’ve included working snippets and pointers to the official Collibra docs for each step.Why centralize the regex?
Storing one canonical regex and referencing it from forms keeps validation consistent and easy to update. Collibra’s Reference Data (Code Sets / Code Values) is designed precisely to hold stable “standards” like patterns you want many places to reuse (for example, formats, identifiers, codes). (Docs: Reference Data basics, Approaches to Reference Data)
Architecture at a glance
Store the regex once in a Code Value attribute (e.g.,
Pattern) inside a Code Set in your Admin community.\ → (Docs: Reference Data basics)Load that pattern into a workflow variable (e.g.,
emailRegex) in a Script task right before your User task.\ → (Docs: Workflow Designer / Dynamic forms tutorial, Java Core API in workflow scripts)Reference the variable from form components:
Validation → Regular expression:
{{emailRegex}}Required:
trueor an expressionMin/Max Length: numeric values
Custom validations (frontend expression):
{{ … }}\ → (Docs: Form examples & expressions, Workflow Designer overview)Step 1 — Store the regex in Reference Data
Code Set:
Message Formats(orValidation Patterns)Code Value: one per pattern, e.g.,
EMAIL,ACCOUNT_ID,PHONEString attribute on Code Value:
Pattern(paste your regex, e.g.,^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$)Step 2 — Load the regex into a workflow variable (Script task)
Place a Script task just before the User task that shows the form. In the script, read the Code Value and its
Patternattribute through the Collibra Java Core API that is available to workflow scripts (e.g.,assetApi,attributesApi). (Docs: Builders / Java API in workflows, AssetApi reference)Groovy script example (Script task):
// Imports depend on version; object names per Java Core API v2 docs
import static com.collibra.dgc.core.workflow.helpers.JavaHelpers.string2Uuid
import com.collibra.dgc.core.api.component.request.attribute.FindAttributesRequest
// 1) Configuration: pass the Code Value UUID via a start/config variable
def codeValueIdStr = (String) execution.getVariable("EMAILCODEVALUEID")
// 2) Get the Code Value asset by UUID
def codeValue = assetApi.getAsset(string2Uuid(codeValueIdStr))
// 3) Read the 'Pattern' attribute value (replace with your attribute type UUID)
def patternAttrTypeId = string2Uuid("00000000-0000-0000-0000-00000000PATTERN") // <-- your UUID
def attrs = attributesApi.findAttributes(
FindAttributesRequest.builder()
.assetId(codeValue.id)
.typeId(patternAttrTypeId)
.build()
).getResults()
if (!attrs || attrs.isEmpty()) {
throw new IllegalStateException("No 'Pattern' attribute found on Code Value ${codeValue.name}")
}
def regex = attrs.get(0).value // the central regex string
// 4) Expose to forms
execution.setVariable("emailRegex", regex)
Step 3 — Reference the regex in the form’s validation properties
Open your User task form → select a Text input field. In Validation:
Required:
true(or an expression like{{age > 18}})Minimum length / Maximum length: numbers
Regular expression: set to the variable from your script, e.g.
{{emailRegex}}Custom validations: any JavaScript expression referencing form variables, e.g.
{{ email.match(new RegExp(emailRegex)) !== null }}Example (conceptual YAML of a Text input component):
# Component: Email
label: Email
variable: email
validation:
required: true # or "{{age>18}}"
minLength: 7
maxLength: 254
regex: "{{emailRegex}}" # references the central pattern
custom: "{{ email.toLowerCase() !== '[email protected]' }}" # extra rule
Using Custom validations effectively (
{{…}})Custom validations let you go beyond regex/length, with frontend expressions evaluated in the browser. If the expression returns
false, the form can’t be submitted—great for cross‑field checks and rule logic.Patterns you can implement:
Combine with the central regex (all in Custom):
validation:
custom: "{{ email && new RegExp(emailRegex).test(email) }}"
Conditional requirements (e.g., only required if a checkbox is on):
validation:
required: "{{ subscribeToEmails === true }}"
custom: "{{ !subscribeToEmails || new RegExp(emailRegex).test(email) }}"
Cross‑field consistency (e.g., ID must start with the two-letter country code selected elsewhere):
validation:
custom: "{{ accountId.startsWith(countryCode) }}"
Form expression and JavaScript guidance: (Docs: Form examples & JavaScript in expressions)
Multiple fields / multiple forms
One script task can load several regexes from different Code Values (e.g.,
emailRegex,acctRegex,phoneRegex) and set variables for the entire form.Every field (across multiple forms/user tasks) can reference those variables via
{{…}}.If different forms need different patterns, expose configuration variables per workflow definition (Start form vars) holding the relevant Code Value UUIDs. This is a proven pattern for configurable values in workflows. (Example pattern: Stack Overflow answer on configurable cron)
Error messaging & user guidance
Collibra’s form components display validation failures inline; for richer guidance you can:
Put helper text/description on a component explaining the expected format.
Use task documentation or a “dummy form element” to show instructions if many fields must be completed. (Good practice write‑ups: Collibra Bytes #4: Dummy form element, Collibra Bytes #6: Mandatory fields & messaging)
In Custom validations, you can guide users by enabling/disabling elements conditionally and by using expressions to mark fields as required only when meaningful. (Docs: Form examples)
End‑to‑end example (centralized EMAIL pattern)
A. Reference Data (Admin):
Code Set:
Message FormatsCode Value:
EMAILAttribute (
Pattern):^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$B. Workflow config (Start form variable):
# Start form variable (readable & writeable so you can set it on the workflow definition page)
id: EMAILCODEVALUEID
type: string
default: "018f…-your-uuid" # UUID of Code Value 'EMAIL'
required: false
readable: true
writeable: true
(Using config vars to control workflow behavior without redeploying is a recommended pattern; see the timer/cron example.)\ (Stack Overflow—configurable timer)
C. Script task (load regex): (as shown above)
D. User task form (field wiring):
# Email field
label: Email
variable: email
validation:
required: true
minLength: 7
maxLength: 254
regex: "{{emailRegex}}" # centralized reference
custom: "{{ email !== 'do-not-use@corp' }}" # extra business rule
Docs supporting the form and expression wiring:
Create a workflow with dynamic forms
Form examples (expressions, JS)
Practical tips & gotchas
Anchors: Include
^and$in your stored pattern if you want whole‑string matches (common for IDs/emails). (Regex basics referenced in form examples and general practice)Escaping: Store the raw regex in the attribute (e.g.,
^\d{10}$). When passing into forms, you reference with{{variable}}; there’s no need to wrap with/…/unless you build aRegExpin a custom validation expression.Performance: Fetch patterns once per User task. Avoid repeated API calls—store them in variables and reuse across fields.
Governance: Update the Code Value’s
Patternattribute to change validation everywhere. Consider approvals/workflows for Reference Data changes. (Docs: Reference Data lifecycle)Mapping to your original fields
You noted the standard validation fields are:
Required → Set
trueor an expression like{{age > 18}}.\ (Docs: Form examples—required via expression)Validation regex →
{{yourCentralRegexVariable}}from the Script task.\ (Docs: Dynamic forms tutorial)Minimum length / Maximum length → enter numeric thresholds.\ (Docs: Workflow Designer overview)
Custom validations → any JavaScript expression
{{ … }}; ideal for cross‑field logic or additional business rules.\ (Docs: Form examples & JavaScript in expressions)Want me to tailor the snippets?
Grant, if you share:
the UUID of your
Patternattribute type, andthe UUIDs of the Code Values you want to reference (or their names and the asset type/domain),
I can generate ready‑to‑paste Script tasks plus form snippets for each field (e.g., 25 fields across your forms), including Custom validations examples to match your business rules.