Regular Expressions

This content applies to legacy design tools (such as K2 Studio, K2 for Visual Studio, or the Silverlight-based K2 workflow design tool). If you have upgraded from K2 blackpearl 4.7 to K2 Five, these tools may still be available in your environment. These legacy tools may not be available in new installations of K2 Five. These legacy tools may also not be available, supported, or behave as described, in future updates or versions of K2. Please see the legacy component support policy for more information about support for these components.

Regular Expressions provide a powerful, flexible, and efficient method for processing text. A regular expression is a pattern that the regular expression engine attempts to match in input text.

An item is selected and then added to the canvas or K2 field part by clicking the Add button or by dragging it to the right place.

Functions Description Example
Match Multiple

To match multiple values from the input string value using a regular expression pattern. e.g. Finding all claim codes in a text form that has “CLM” in front followed by a fixed 5 digit number.

Input – Input text to search on. This is a string type.

Regex Pattern – Regular expression pattern to use for the search.

Case Sensitive – Option to indicate whether the search should be case sensitive or not.

Return value (String[]) - is the array of string values that matched the pattern. If there is no match, it returns No match found.

Example 1:
Input: "example"
Pattern: "[a-z]*"
Case Sensitive: "true"
Result: { "example" }

Example 2:
Input: "Example"
Pattern: "[a-z]*"
Case Sensitive: "true"
Result: { "xample" }

Example 3:
Input: "example"
Pattern: "[a-z]*"
Case Sensitive: false
Result: { "example" }

Example 4:
Input: "Example"
Pattern: "[a-z]*"
Result: { "Example" }

Match Single

To match a single value string from the input string value using a regular expression pattern. e.g. Finding a user’s name specified in a text form.

Input – Input text to search on. This is a string type.

Regex Pattern – Regular expression pattern to use for the search.

Case Sensitive – Option to indicate whether the search should be case sensitive or not.

Expected When Empty – String type. This is returned when there is no match found or the matched value is empty.

Return value (String) - is the matched string if there is a match.

Example 1:
Input: "Example"
Pattern: "[a-z]*"
Case Sensitive: true
Expected When Empty: "empty"
Result: "empty"

Example 2:
Input: "An example"
Pattern: "\\b\\w+es\\b"
Case Sensitive: true
Expected When Empty: "empty"
Result: "empty"

Example 3:
Input: "example;"
Pattern: "[a-z]*"
Case Sensitive: true
Expected When Empty: "empty"
Result: "example"

Example 4:
Input: "Example"
Pattern: "[a-z]*"
Case Sensitive: false
Expected When Empty: "empty"
Result: "Example"

Example 5:
Input: "example"
Pattern: "[a-z]*"
Expected When Empty: "empty"
Result: "example"

Match

For doing a regular expression pattern match of a value. e.g. to check if the input value is a valid E-mail address.

Input – Input text to search on. This is a string type.

Regex Pattern – Regular expression pattern to use for the search.

Case Sensitive – Option to indicate whether the search should be case sensitive or not.

Return value (Boolean) - is true if a match was found, otherwise false.

Example 1:
Input: "Examples"
Pattern: "(es)", "(\b\w+es\b)", or "\b\w+(es)\b"
Case Sensitive: true
Result: true

Example 2:
Input: "Example"
Pattern: "(es)", "(\b\w+es\b)", or "\b\w+(es)\b"
Case Sensitive: true
Result: false

Example 3:
Input: ""
Pattern: "[a-z]*"
Case Sensitive: true
Result: true

Note that * will always return a match

Example 4:
Input: ""
Pattern: "[a-z]"
Case Sensitive: true
Result: false

Example 5:
Input: "Examples"
Pattern: "(es)", "(\b\w+es\b)", or "\b\w+(es)\b"
Case Sensitive: false
Result: true

Matches words ending in 'es'

Example 6:
Input: "Example"
Pattern: "(es)", "(\b\w+es\b)", or "\b\w+(es)\b"
Case Sensitive: false
Result: false

Matches words ending in 'es'