Function "replace"

Summary

Replaces in a string every part that matches a specified regular expression with another string. The function belongs to the group "Text".

The return type is text.

Allowed number of parameters are 3.


Parameters

Parameter Description
1 String to be processed.
2 regular expression
3 Replacement string.



Attention with regular expressions!

The QiQu-Function 'replace' uses the method 'replace' of the Java String class. The Java String the forwards the parameters to an regular expression engine. The problem is, that all three levels (QiQu, Java and and the Regular-Expression engine) are using the same escape sequenz für a backslash \.

This can lead to some confusion. Consider the following example. You've got a string which defines a package name. Now, you'd like to replace all '.' with a backslash. How does your replace-function call has to look?

In java we would write something like this: "ch.alob.qiqu".replace(".", "\\\\"). Since we are in Java-code, we need to escape a '\' with '\\'. Next, the second parameter of th replace-Method of String is a regular expression itself. Meaning wie have to escape it another time. Therfore, "\\\\" is the second parameter. Now, QiQu adds another level, where the a '\' has to be escaped. Therfore, a value-expression parameter of a QiQu-Command will like as follows:

<Set Ref="aNewProperty" Value="replace('ch.aloba.qiqu', '.', '\\\\\\\\')"/>