Part of expression substitution

With this option, only part of each selected expression is replaced rather than the whole expression. The part of the expression to be replaced is specified by a Regular Expression match.

About this task

It is possible that more that one part of an expression string could match the Regular Expression specified. If Replace all occurrences is checked, then each occurrence of a match will be updated with the replacement value specified. If it is not checked, then just the first occurrence is replaced.

When replacing part of an expression, the replacement value specified can include that part of the original expression being replaced. In order to do this, the Regular Expression specified must have round brackets around its value. "$1" in the replacement value will then represent that matched text. If the Regular Expression is not surrounded by round brackets, then "$1" will simply be the text "$1".

For complex Regular Expression usage, subsets of the Regular Expression text can be included in round brackets rather than the whole text. In this case, the entire matched part of the original expression is still replaced, but "$1", "$2" etc can be used to refer to each matched bracketed part of the Regular Expression specified.

The following is an example of the Part of expression replacement.

Suppose a selected set of columns have derivations that use input columns from `DSLink3'. For example, two of these derivations could be:

DSLink3.OrderCount + 1
If (DSLink3.Total > 0) Then DSLink3.Total Else -1

You might want to protect the usage of these input columns from null values, and use a zero value instead of the null. Use the following procedure to do this.

Procedure

  1. Select the columns you want to substitute expressions for.
  2. Select the Part of expression option.
  3. Specify a Regular Expression value of:
    (DSLink3\.[a-z,A-Z,0-9]*)
  4. Specify a replacement value of
    NullToZero($1)
  5. Click OK, to apply this to all the selected column derivations.

Results

From the examples above:

DSLink3.OrderCount + 1

would become

NullToZero(DSLink3.OrderCount) + 1

and

If (DSLink3.Total > 0) Then DSLink3.Total Else -1

would become:

If (NullToZero(DSLink3.Total) > 0) Then DSLink3.Total Else -1

If the Replace all occurrences option is selected, the second expression will become:

If (NullToZero(DSLink3.Total) > 0) 
Then NullToZero(DSLink3.Total) 
Else -1

The replacement value can be any form of expression string. For example in the case above, the replacement value could have been:

(If (StageVar1 > 50000) Then $1 Else ($1 + 100))

In the first case above, the expression

DSLink3.OrderCount + 1

would become:

(If (StageVar1 > 50000) Then DSLink3.OrderCount 
Else (DSLink3.OrderCount + 100)) + 1