activities
latest
false
UiPath logo, featuring letters U and I in white
Workflow Activities
Last updated Nov 18, 2024

VerifyIsRegexMatch

Verifies if the first expression is a regex match to the second expression.

Definition

Namespace: UiPath.Testing.API

Assembly: UiPath.Testing.Activities.Api (in UiPath.Testing.Activities.Api.dll)

VerifyIsRegexMatch(object, object, string)

bool VerifyIsRegexMatch(
       object firstExpression
       object secondExpression
       string outputMessageFormat = null
)bool VerifyIsRegexMatch(
       object firstExpression
       object secondExpression
       string outputMessageFormat = null
)
firstExpression Object
The first expression in the verification process. This is the string or other object that you want to verify if it matches a regex expression.
secondExpression Object
The second expression in the verification process. This is the regex expression that the firstExpression should match.
outputMessageFormat String
The format of the output message. The supported arguments are:
  • {LeftExpression}
  • {LeftExpressionText}
  • {RightExpression}
  • {RightExpressionText}
  • {Result}

For more information, check the Configuring the outputMessageFormat section.

Return value

It is True if the first expression is a regex match to the second expression , and False if the first expression is not a regex match to the second expression.

Examples

Check the following code examples for using the VerifyIsRegexMatch API.
  1. Example 1: Check if a string is a valid email address.
    string email = "[email protected]";
    string emailRegex = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
    bool isEmailValid = testing.VerifyIsRegexMatch(email, emailRegex);string email = "[email protected]";
    string emailRegex = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
    bool isEmailValid = testing.VerifyIsRegexMatch(email, emailRegex);
  2. Example 2: Check if a string contains any digits.
    string text = "Hello, World 123!";
    string digitRegex = @"\d";
    bool containsDigits = testing.VerifyIsRegexMatch(text, digitRegex);string text = "Hello, World 123!";
    string digitRegex = @"\d";
    bool containsDigits = testing.VerifyIsRegexMatch(text, digitRegex);
  3. Example 3: Check if a string is a valid hex color code.
    string color = "#FF5733";
    string hexColorRegex = "^#(?:[0-9a-fA-F]{3}){1,2}$";
    bool isColorValid = testing.VerifyIsRegexMatch(color, hexColorRegex);string color = "#FF5733";
    string hexColorRegex = "^#(?:[0-9a-fA-F]{3}){1,2}$";
    bool isColorValid = testing.VerifyIsRegexMatch(color, hexColorRegex);

Configuring the outputMessageFormat

The outputMessageFormat parameter can be configured with supported arguments, that act as placeholders for the values used in the verification operation. These placeholders are automatically populated with the variables or values defined when invoking the API at runtime.

For the VerifyRange API, you can implement the following supported arguments when creating an output message:

  • {LeftExpression}: Represents the value of the first expression you provided for the firstExpression parameter.
  • {LeftExpressionText}: Represents the text of the first expression you inserted for the firstExpression parameter.
  • {RightExpression}: Represents the value of the second expression you provided for the secondExpression parameter.
  • {RightExpressionText}: Represents the text of the second expression you inserted for the secondExpression parameter.
  • {Result}: Represents the API's return value, which is the verification result.
The following is an example on how to use the VerifyIsRegexMatch API, which includes configuring the outputMessageFormat parameter:
// Initialize variables for the expressions to be verified
var expression1 = "(\W|^)stock\stips(\W|$)";
var expression2 = "(\W|^)stock\s{0,3}tips(\W|$)";

// Employ the VerifyIsRegexMatch API, with the last string parameter being the outputMessageFormat
testing.VerifyIsRegexMatch(expression1, expression2, "{LeftExpression} should match {LowerLimitText}, but the result is {Result}.");// Initialize variables for the expressions to be verified
var expression1 = "(\W|^)stock\stips(\W|$)";
var expression2 = "(\W|^)stock\s{0,3}tips(\W|$)";

// Employ the VerifyIsRegexMatch API, with the last string parameter being the outputMessageFormat
testing.VerifyIsRegexMatch(expression1, expression2, "{LeftExpression} should match {LowerLimitText}, but the result is {Result}.");

In the provided example, the placeholders within the curly brackets are replaced with the corresponding variable names and their values at runtime, providing a customized output message.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.