ModifierStr Property

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

Use the RegExpr.ModifierStr property to turn on and off modifiers applied to the regular expressions. The following modifiers are available:

Modifier key Default state Description
i Enabled Makes the pattern match case-insensitive.
m Disabled Treats string as multiple lines. In this mode, the caret ^ and dollar $ match before and after newlines in the subject string. See also Line separators .
s Enabled Treats string as single lines. In this mode, the dot matches new lines. See also Line separators.
g Enabled

Controls greedy mode. Non-standard modifier.

"Greedy" repetition operator takes as many matching characters as possible, "non-greedy" takes as few as possible. For example, b+ and b* applied to string abbbbc will return bbbb, where as b+? will return b and b*? will return an empty string.

Switching into non-greedy mode makes + work as +?, * as *? and so on.

x Disabled

Permits whitespaces and comments in the pattern. Non-standard modifier.

In this mode, the whitespaces (\s) that are neither backslashed nor within a character class are ignored. You can use this to break up your regular expression into more readable parts. Also the # character is treated as a metacharacter introducing a comment. For example:

  ( # This pattern matches
    (this) # the occurrence of 'this'
      | # or
    (that) # the occurrence of 'that'
  )

If you want to place a whitespace or # characters in the pattern, then you have to prefix them with / or encode them using hex notations (\xNN).

Declaration

RegExprObj.ModifierStr

Read-Write Property String
RegExprObj An expression, variable or parameter that specifies a reference to a RegExpr object

Applies To

The property is applied to the following object:

Property Value

The string that contains any combination of modifier keys.

If a modifier key is prefixed with the minus sign the modifier turns off. For example, ModifierStr := 'ig-s' enables case-insensitive matching and greedy mode and disables single-line mode.

Remarks

To apply modifiers inside a regular expression or to a part of the regular expression specify a modifier keys within the (? ) structure. For example, expression (?i)te(?-i)st should match test and TEst, but not teST or TEST.

If you try to specify unsupported modifier keys an error occurs.

Example

The following example specifies a regular expression’s modifier to make the pattern case-insensitive and to enable the multiline mode. It finds the first words in all the lines that start with “l” or “L”.

DelphiScript

procedure ModifyerSample;

var
  MyRegExpr : OleVariant;
  Modifier: string;
  Input, Expr, ResStr: string;
begin

  MyRegExpr := HISUtils.RegExpr;
  Input := 'L' + #13 + 'line' + #13 + 'string';
  MyRegExpr.InputString := Input;
  // Specifies a regular expression's modifier
  // Makes the pattern case-insensitive and enables the multiline mode
  MyRegExpr.ModifierStr := 'mi';
  // Specifies patters for lines that starts with "l"
  MyRegExpr.Expression := '^L([\w]+)*( +[\w]+)*';

  if MyRegExpr.Exec(Input) then
    begin
      repeat
        ResStr := MyRegExpr.Match[0];
        // Posts a line that starts with "l" to the log
        Log.Message(ResStr);
      until not MyRegExpr.ExecNext
    end;

end;

See Also

Regular Expressions Syntax
Using Regular Expressions in Scripts
InputString Property

Highlight search results