B.3 Regular Expression Symbols
B.3.1 Regex Dialect and Matching Behavior
The CBA ItemBuilder uses JavaScript regular expressions (ECMAScript/ECMA-262 standard) at runtime. Both the matches() operator (used in FSM conditions, Conditional Links, and Scoring) and the Input Validation Pattern (used for restricting text input in SingleLineInputField and InputField components) use the same regex engine.
abc will match any text that contains abc (e.g., xabcy). To match the complete text, always use ^ at the beginning and $ at the end of the pattern: ^abc$.
Key characteristics:
Multiline flag (
m): The regex engine uses the JavaScriptm(multiline) flag. This means^matches the beginning of each line and$matches the end of each line (not only the beginning and end of the entire string).Partial matching: The
matches()operator and Input Validation Pattern both perform partial matching. The patternabmatchesabcbecauseabis found withinabc. For full-string matching, use^ab$.Case sensitive: Matching is case-sensitive by default. To match case-insensitively, use character classes like
[Aa]bcor[a-zA-Z].Error handling: If an invalid regex pattern is used, the
matches()operator returnsfalse(the condition is not met), while the Input Validation Pattern returnstrue(the input is accepted without validation).Escaping in CBA ItemBuilder syntax: When writing regex patterns in CBA ItemBuilder syntax (FSM, Conditional Links, Scoring), backslashes must be doubled: Write
\\dto match a digit,\\sfor whitespace,\\.for a literal dot.
B.3.2 Common Regex Patterns for CBA ItemBuilder
| Purpose | Pattern | Explanation |
|---|---|---|
| Exact text match | ^correct answer$ |
Matches only the exact text “correct answer” |
| Case-insensitive match | ^[Cc]orrect [Aa]nswer$ |
Matches “correct answer”, “Correct Answer”, etc. |
| Non-empty input | ^.+$ |
Matches any text with at least one character |
| Only digits | ^[0-9]+$ |
Matches one or more digits |
| Only letters | ^[a-zA-Z]+$ |
Matches one or more letters (no spaces, no digits) |
| Integer number | ^-?[0-9]+$ |
Matches positive or negative integers |
| Decimal number | ^-?[0-9]+(\\.[0-9]+)?$ |
Matches integers and decimal numbers |
| Maximum length (e.g., 5) | ^.{0,5}$ |
Matches any text of 0 to 5 characters |
| Exact length (e.g., 3) | ^.{3}$ |
Matches any text of exactly 3 characters |
| One of several words | ^(cat\|dog\|bird)$ |
Matches exactly “cat”, “dog”, or “bird” |
| Starts with a letter | ^[a-zA-Z] |
Text must start with a letter |
| No digits allowed | ^[^0-9]*$ |
Matches text without any digits |
| Allow empty or single letter | ^[a-zA-Z]?$ |
Matches empty string or a single letter |
B.3.3 Input Validation Pattern Tips
When using the Input Validation Pattern property of SingleLineInputField or InputField components (see section 6.1.3), the pattern is checked on every keystroke. If the new text does not match the pattern, the keystroke is rejected and the input remains unchanged.
^ and $ anchors to validate the complete input text. Without anchors, any input that contains a matching substring will be accepted.
Common pitfall: A validation pattern of [0-9] does not restrict input to digits only—it accepts any text that contains at least one digit (e.g., abc1xyz). Use ^[0-9]*$ instead to allow only digits (including empty input) or ^[0-9]+$ to require at least one digit.
B.3.4 Regular Expression Symbol Reference
| Symbols | Description |
|---|---|
. |
Matches any character except line breaks. |
^ |
Beginning. Matches the beginning of the string or of a line (with multiline flag). |
$ |
End. Matches the end of the string or of a line (with multiline flag). |
() |
Capturing group. Groups multiple expressions together. |
{n} |
Quantifier. Matches exactly n repetitions of the preceding token. |
{x,y} |
Quantifier. Matches between x and y repetitions of the preceding token. |
[] |
Character set. Matches any single character in the set. |
[^] |
Negated set. Matches any single character that is not in the set. |
\| |
Alternation. Matches the expression before or after the \|. |
? |
Optional. Matches 0 or 1 of the preceding token. |
+ |
One or more. Matches 1 or more of the preceding token. |
* |
Zero or more. Matches 0 or more of the preceding token. |
\\ |
Escape. Matches the character after the \\ literally. |
(?:) |
Non-capturing group. Groups tokens without creating a capture group. |
\\\\ |
Matches a literal backslash character. |
[a-z] |
Range. Matches any character from a to z (lowercase). |
[A-Z] |
Range. Matches any character from A to Z (uppercase). |
[0-9] |
Range. Matches any digit from 0 to 9. |
[a-zA-Z0-9] |
Matches any alphanumeric character. |
[^a-z] |
Matches any character except lowercase letters. |
\\d |
Digit. Matches any digit character, equivalent to [0-9]. |
\\D |
Not digit. Matches any non-digit character, equivalent to [^0-9]. |
\\s |
Whitespace. Matches any whitespace character (spaces, tabs, line breaks). |
\\S |
Not whitespace. Matches any non-whitespace character. |
\\w |
Word character. Matches any alphanumeric character or underscore, equivalent to [a-zA-Z0-9_]. |
\\W |
Not word character. Matches any non-word character, equivalent to [^a-zA-Z0-9_]. |
\\n |
Matches a line break (newline) character. |
\\t |
Matches a tab character. |