Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

matlab.unittest.constraints.Matches class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Constraint specifying string matches regular expression

Construction

Matches(expr) creates a constraint that specifies that a string scalar or character vector matches a regular expression. The constraint is satisfied only if the actual value matches the given regular expression, expr.

Matches(expr,'IgnoringCase',caseInsensitive) creates a constraint indicating whether to ignore case difference.

Input Arguments

expr

Regular expression that the actual value must match to satisfy the constraint, specified as a string scalar or character vector. expr can include newline characters.

caseInsensitive

Indicator if the constraint is insensitive to case, specified as false or true (logical 0 or 1)

Default: false

Properties

Expression

Regular expression that the actual value must match, specified in the input argument, expr.

IgnoreCase

Indicator if the constraint is insensitive to case, specified in the input argument, ignoreCase. This property applies at all levels of recursion, such as nested structures.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Examples

expand all

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.Matches

testCase = TestCase.forInteractiveUse;

Test that the actual value string, 'Epsilon Eridani', matches 'eps'.

testCase.verifyThat('Epsilon Eridani', Matches('^eps'))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
Matches failed.
--> The value does not match the regular expression.

Actual char:
    Epsilon Eridani
Regular Expression:
    ^eps

To satisfy the constraint, configure it to be case insensitive.

testCase.verifyThat('Epsilon Eridani', Matches('^eps', ...
    'IgnoringCase', true))
Interactive verification passed.

Define the regular expression that the actual value must match.

expr = 'Some[Tt]?ext';

The [Tt]? contained in the regular expression indicates that either 'T' or 't' matches at that location 0 or 1 times.

Test that the actual values, 'SomeText' and 'Sometext', satisfy the constraint.

testCase.verifyThat('SomeText', Matches(expr))
testCase.verifyThat('Sometext', Matches(expr))
Interactive verification passed.
Interactive verification passed.

Test that the actual value 'Someext' satisfies the constraint.

testCase.verifyThat('Someext', Matches(expr))
Interactive verification passed.

Test that the actual value 'sometext' does not satisfy the constraint.

testCase.verifyThat('sometext', Matches(expr))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
Matches failed.
--> The value does not match the regular expression.

Actual char:
    sometext
Regular Expression:
    Some[Tt]?ext
Was this topic helpful?