Regular Expressions (RegExp / Regex)

What are regular expressions and how are they used?

Product line

Standard

|

Expert

Operating mode

CLOUD ABO

|

ON-PREMISES

Modules

Services & CRM

Budget & Phases

Purchases

Resource Planning

Business Intelligence

Created: 04.05.2004
Machine translated
Updated: 07.08.2019 | Title supplemented with the terms RegExp and Regex.

The OCL operators regExpMatch and replaceRegex use regular expressions.

On the internet you can find a lot of information about regular expressions. Here as an example the article Regular Expression in Wikipedia. A good implementation can also be found at the following link: http://www.regular-expressions.info/

In Vertec, the basic elements (., *, +, [, ], ^, $, –, \) can be used:

.Any single character. Example: h.t matches hat, hit, hot and hut.
[ ]Any one of the characters in the brackets, or any of a range of characters separated by a hyphen (-).

Examples: h[aeiou][a-z] matches hat, hip, hit, hop, and hut; x[0-9] matches x0, x1, ..., x9.

[^]Any characters except for those after the caret “^”.

Example: h[^u]t matches hat, hit, and hot, but not hut.

^The start of a line.
$The end of a line (not the line break characters). Use this for restricting matches to characters at the end of a line.

Example: end$ only matches “end” when it’s the last word on a line, and ^end only matches “end” when it’s the first word on a line.

*Matches zero or more of the preceding characters or expressions.

Example: ho matches hp, hop and hoop.

+Matches one or more of the preceding characters or expressions.

Example: ho+p matches hop, and hoop, but not hp.

\“Escapes” the special meaning of the above expressions, so that they can be matched as literal characters. Hence, to match a literal “\,” you must use “\\”.

Collection Of Examples

Checks whether a phone number consists only of digits. Spaces and '-' are allowed.

standardtelefon.regExpMatch('^[0-9 -]*$')

Represents an addresstext in a row, the rows are separated by commas:

oclastype(Adresseintrag).adresstext.replaceregex('\r\n',', ').replaceregex('\n',', ')

Abbreviates the first name of the user (first name and last name are in the same field):

name.replaceregex('.*\s+', name.substring(0,0)+'. ')

Result:

Hans Muster -> H. Muster
Hans P. Muster -> H. Muster

Search in all addresses for all Mayers, Mejers, Maiers, Meyers etc.:

adresseintrag->select(name->regExpMatch('M[ae][ijy]er'))

Displays in a column on a list of companies from the company name only what is in brackets:

if name.sqllike ('%(%') then name.replaceRegex('^.*\(','').replaceregex('\)$','') else '' endif

Result:

Test company (additional information) -> Additional information

Displays in a column on a list of companies from the company name only what is not in brackets:

name.replaceregex('\(.*\)$','')

Result:

Test company (additional information) -> Test company