Create complex expressions using natural language

Even if you are not familiar with the syntax, BlazeMeter helps you create complex expressions to match transactions seamlessly by letting you use natural language.

A common use case is matching dynamic URL patterns or request or response bodies of transactions. The AI  assistant can generate sophisticated expressions for Wiremock Handlebars, regular expression (regex), and xpath, which are commonly used in headers, response matchers, and request matchers in transactions fields.

Like other AI-assisted features, the AI expression assistant requires explicit consent and opt-in. See Manage AI Consent and the Perforce Generative AI Policy for more details.

For an alternative method using a wizard, see also Generate paths for request matching and dynamic responses.

For general information about how to match requests and define responses, see Add transactions.

Motivation

When filling in matcher fields without the expression assistant, you would need to know regular expression syntax, write the regex in an external tool, test the expression externally, copy and paste it into the URL field, redeploy the virtual service, retest the virtual service, and repeat the cycle if the regex didn't match as expected.

Using the built-in assistant speeds up this process considerably. Describe what you need in natural language, and the AI generates the appropriate expression along with a plain-English explanation of why it works. Either append the generated expression to an existing value, override the current field content, or simply copy it to the clipboard and use it elsewhere.

Supported Languages

The AI Assistant helps you generate the following expression types:

  • Regular expressions (regex) — for pattern-based URL or value matching

  • XPath — for matching content within XML bodies

  • JSONPath — for matching content within JSON bodies

  • Handlebars — for dynamic Wiremock-style response templating

Supported input fields

The expression assistant is available in the following input fields of a transaction:

In the Request Matcher tab:

  • URL—Match incoming request URLs using regex or exact patterns

  • Headers—Match specific request header names and values

  • Query Parameters—Match URL query string parameters and their values

  • Cookies—Match cookie names and values in the request

  • Body—Match request body content using regex, xpath, jsonpath, or handlebars

In the Response tab:

  • Headers—Define dynamic or pattern-based response header values

  • Body—Generate dynamic response body content using handlebars or other expressions

Generate a matching expression

You are creating a transaction that requires a flexible matching pattern in a field, but you don't know how to write the correct matching expression.

  1. Edit the transaction in the Asset Catalog.

  2. Navigate to the Request Matcher or Response tab.

  3. Click the button to open the AI assistant for the field you are defining.

  4. (Optional) Try the suggestions to see what the assistant can do for you.

  5. Type in your requirements for the expression in natural language.
    Example: "Match a URL path that starts with /pet/ followed by a five digit number"
    The assistant displays a suggested regular expression:
    /pet/\d\d\d\d\d$
  6. Validate the generated expression by entering sample data in the second field.
    Example: /pet/00158 validates, /pet/158 and /cat/34611 do not validate.

  7. Choose one of the following actions:

    • Append — To add the generated expression to any existing content in the field

    • Override — To replace the current field content with the generated expression

    • Copy — To copy the expression to your clipboard for use elsewhere, and leave the field as is.

Each time the modal is opened on a different field, it starts fresh — the context is scoped to the field currently being edited.

Examples

User: Give me a regex to match URLs with the pattern /book- followed by an alphanumeric ID

Assistant: ^/book-[a-zA-Z0-9]+$

User: Why does this work?

Assistant: This regex matches URIs that start with /book- followed by one or more alphanumeric characters for the ID, and nothing else. The ^ and $ anchors ensure the entire string matches the pattern.

 

User: Give me a regex to match the Content-Type header when it contains application/json but could also have parameters like charset=utf-8

Assistant: ^Content-Type:\s*application/json(?:;[^,\r\n]*)?$