aqString.StrMatches Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

The aqString.StrMatches method lets you test a string against a regular expression. The method returns True if the string contains a substring that matches the specified pattern and False otherwise.

Declaration

aqString.StrMatches(ExprStr, Str)

ExprStr [in]    Required    String    
Str [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

ExprStr

Specifies a regular expression pattern to be sought for in the string. For information about constructing patterns, see Regular Expressions Syntax.

Str

The string on which the search will be performed.

Result Value

True if the Str string contains a substring that matches the ExprStr pattern. Otherwise False.

Remarks

To search for an ordinary substring within a string, use the aqString.Find method.

Example

The following code searches for the occurrences of "get" or "got" in three different sentences.

JavaScript, JScript

function StrMatchesSample()
{
  Log.Message( aqString.StrMatches("g[eo]t", "John has got a good mark.") )   // Posts True
  Log.Message( aqString.StrMatches("g[eo]t", "Where did you get this?") )     // Posts True
  Log.Message( aqString.StrMatches("g[eo]t", "There was a cow and a goat.") ) // Posts False
}

Python

def StrMatchesSample():
  Log.Message(aqString.StrMatches("g[eo]t", "John has got a good mark.")) # Posts True
  Log.Message(aqString.StrMatches("g[eo]t", "Where did you get this?")) # Posts True
  Log.Message(aqString.StrMatches("g[eo]t", "There was a cow and a goat.")) # Posts False

VBScript

Sub StrMatchesSample
  Log.Message( aqString.StrMatches("g[eo]t", "John has got a good mark.") )   ' Posts True
  Log.Message( aqString.StrMatches("g[eo]t", "Where did you get this?") )     ' Posts True
  Log.Message( aqString.StrMatches("g[eo]t", "There was a cow and a goat.") ) ' Posts False
End Sub

DelphiScript

procedure StrMatchesSample;
begin 
  Log.Message( aqString.StrMatches('g[eo]t', 'John has got a good mark.') );   // Posts True
  Log.Message( aqString.StrMatches('g[eo]t', 'Where did you get this?') );     // Posts True
  Log.Message( aqString.StrMatches('g[eo]t', 'There was a cow and a goat.') ); // Posts False
end;

C++Script, C#Script

function StrMatchesSample()
{
  Log["Message"]( aqString["StrMatches"]("g[eo]t", "John has got a good mark.") )   // Posts True
  Log["Message"]( aqString["StrMatches"]("g[eo]t", "Where did you get this?") )     // Posts True
  Log["Message"]( aqString["StrMatches"]("g[eo]t", "There was a cow and a goat.") ) // Posts False
}

See Also

Working With Strings
Find Method
Regular Expressions Syntax

Highlight search results