regExpSplit lets you split a string into separate text values wherever a regular-expression pattern matches. Use it in OCL when a fixed delimiter is not enough—for example, when input may contain commas, semicolons, or varying whitespace.
Syntax
<em>text</em>.regExpSplit('<em>regular-expression</em>')textis the string to split.regular-expressiondescribes each split position or delimiter.- The result is a collection of the text parts. You can process those parts further or format them as a string.
Split on several delimiters
Use a character class, [...], to match one of several delimiter characters. Add + when consecutive delimiters should be treated as one split.
'dskjfkjsd sd;kfkl sdl,fkjf ds'.regExpSplit('[,\s;]+')This pattern means:
| Pattern part | Meaning |
|---|---|
[,\s;]
|
Match a comma, whitespace character, or semicolon. |
+
|
Match one or more consecutive occurrences of those delimiters. |
The expression splits the input at spaces, the semicolon, and the comma. Because the pattern includes +, a run of delimiters is handled as one split rather than as separate split points.
Add spaces to a combined identifier
You can also split at a position rather than consume a delimiter. The following expression inserts split positions in a combined identifier and then joins the parts with spaces:
('ReadyForSpaceAndTurnItReadebleText').regExpSplit('(?<!^)(?=[A-Z][a-z]|(?<=[a-z])[A-Z])')->asSeparatedList(' ')The resulting formatted text is:
Ready For Space And Turn It Readeble Text
The regular expression uses lookarounds to find the boundary before a new word:
| Pattern part | Meaning |
|---|---|
(?<!^)
|
Do not split at the beginning of the string. |
(?=[A-Z][a-z])
|
Split before an uppercase letter that starts a word followed by lowercase letters. |
(?<=[a-z])[A-Z]
|
Split where an uppercase letter follows a lowercase letter. |
Use asSeparatedList(' ') when you need one display string. Keep the result of regExpSplit as a collection when you need to handle each part separately, such as when building a collection of strings.
Choose the right operation
| Need | Use |
|---|---|
| Split a string at pattern-based delimiters or boundaries | regExpSplit
|
| Check or find text that matches a regular expression | regExpMatch |
| Split a string into individual characters | ToCharArray |
| Create a fixed collection of distinct values | Set |
