What are regular expressions and how are they used?
Operating mode
Cloud Suite
|ON-PREMISES
Modules
Services & CRM
Budget & Phases
Purchases
Resource Planning
Business Intelligence
The OCL operators regExpMatch and replaceRegex use regular expressions.
There is a lot of information on regular expressions on the internet. Here is an example of 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 “\\”. |
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 from the written name on the user (first name and last name are in the same field): name.replaceregex('.*\s+', name.substring(0,0)+'. ') Result: Hans Muster -> H. Muster |
Finds all users named Meier, Mayer, Mejer, Maier, Meyer etc.: projektbearbeiter->select(name->regExpMatch('M[ae][ijy]er')) |
Displays in a column in a list of companies by company name only what is in parentheses: if name.sqllike ('%(%') then name.replaceRegex('^.*\(','').replaceregex('\)$','') else '' endif Result: Test company (additional information) -> Additional information |
Displays in a column in a list of companies by company name only what is not in parentheses: name.replaceregex('\(.*\)$','') Result: Test company (additional information) -> Test company |