|The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....|
|Home BasePack Streams Procedures and Functions SearchAndReplace|
|See also: TGrep, FindInStream, ExtractFromStream, TSRUnknownModifierEvent, ExpandDiphthongs|
The function SearchAndReplace is a powerful search and replace function which replaces any characters of the input stream InStream matching the search expression SearchExp by the replacement expression ReplaceExp. The search expression may be a regular expression. If the parameter IgnoreCaseis TRUE the search is not case sensitive. The replacement expression may be any character string and may contain any number of place holders for the first 9 regular expression tokens of the search expression. The place holders are identified by the character combination @n, with n being a number between 1 and 9 (a double @ character in the replacement string has to be used for inserting @ characters). Replacement substrings addressed by the @-syntax may be modified before reinserting it into the output stream by the following modifiers:
Modifiers have to precede the replacement token and are only valid for this particular token. You may define custom modifiers simply by inserting an unknown modifier (one that does neither constitute a replacement token nor one of the modifiers listed above) before a replacement token. If an unknown modifier is encountered the callback function OnUnknownModifier is called. The callback function receives both the modifier and the replacement token to be modified. Please note that modifiers must not be specified without a corresponding replacement token. Doing so will result in erroneous results. If you want to use a modifier which does not "modify" anything but adds extra information into the replacement string (for example, a running number) you have to use the replacement token @0 which is always empty.
In addition to the powerful regular expressions the replace process may be controlled by a condition which is defined by the parameter CondToken, Combination, and CondText. The parameter CondToken specifies the regular expression token which is the basis for the condition. There are four possible conditions, specified by the parameter Combination:
If CondToken is set to a zero value, the evaluation of the condition is switched off.