🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators regExpMatch
This page was created by Stephanie on 2025-01-09. Last edited by Wikiadmin on 2026-07-29.

You can use regExpMatch in OCL to test whether a string matches a regular-expression pattern; it is for modelers who need a Boolean condition for validation, filtering, or other logic.

Syntax

stringExpression.regExpMatch(pattern)

regExpMatch returns a Boolean value:

Result Meaning
true The string matches the regular-expression pattern.
false The string does not match the pattern.

The value before .regExpMatch(...) is the string to test. The argument is the regular-expression pattern.

Match an email-shaped value

Use ^ and $ when the whole value must conform to the pattern. In the following example, the anchors require the match to start at the first character and end at the last character:

'åke.öberg@mdriven.se'.regExpMatch('^[a-öA-Ö0-9+_.-]+@[a-öA-Ö0-9.-]+\.[a-zA-Z]{2,3}$')

This expression returns true.

The pattern has these parts:

Pattern part What it checks
^[a-öA-Ö0-9+_.-]+ The value starts with one or more allowed characters before @.
@ An at sign is required.
[a-öA-Ö0-9.-]+ One or more allowed domain characters are required.
\. A literal dot is required before the final part.
[a-zA-Z]{2,3}$ The value ends with two or three letters.

For the regular-expression syntax and this validation example, see Documentation:Regular expressions.

Use the Boolean result

Because regExpMatch returns a Boolean value, you can use it wherever an OCL condition is required. For example, this expression tests whether a value has the email-shaped format shown above:

self.Email.regExpMatch('^[a-öA-Ö0-9+_.-]+@[a-öA-Ö0-9.-]+\.[a-zA-Z]{2,3}$')

Combine this result with other conditions through OCL Boolean operators when your rule has more than one requirement.

Match versus split

Use regExpMatch when you need a true or false answer about a string. Use regExpSplit when you need to divide a string at positions identified by a regular expression.

For example, use regExpMatch to check a format; use regExpSplit to separate text on commas, semicolons, or spaces.

See also