# Regular Expression Matcher

You can also use regular expressions if you need to match a particular JSON structure. This is useful if you have various similar request payloads that you cannot discern using JSON, JSON Partial or JSONPath matchers. For example, if you need to match on the existence of a number of certain keys and you do not know their values.

Be aware that the regular expression engine is written in GO and conventions used by that language must be used. In particular it does not support Lookahead or Lookbehind assertions.

### Regular expression matching example:

In this example the regular expression will match provided there is a transactionId with a value of 1000, a store, a clientUniqueId and Items. If any are missing it will not match.

This would not be possible with JSONPartial as the values of store, clientUniqueId and items are variable and not known and cannot be specified in a JSON snippet. Only transactionId is known.

JSONPath cannot currently be used if configured through the Hoverfly Cloud editor as it would only be able to return the existence of a single JSON key at a position within the document. Hoverfly does support matcher chaining which will allow you to chain a number of matchers together, however the Hoverfly Cloud editor does not yet support this yet, and if you would prefer to use this method over regular expressions you will need to manually edit the Hoverfly Simulation as described [here](https://docs.hoverfly.io/en/latest/pages/reference/hoverfly/request_matchers.html#matcher-chaining).)

It should be noted that the regular expression can only check for JSON keys that are in the order stated in the matching string. It will not match if they are in a different order in the payload. The GO regexp package used in Hoverfly does not support Lookahead or Lookbehind assertions.

| **Matcher value**                                                  | **Positive payload**                                                                                                                                                                                                       | <p><strong>Non match payload</strong></p><p><strong>(missing store)</strong></p>                                                                                                                                          |
| ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| (?s).\*("transactionId": 1000).\*store.\*clientUniqueId.\*items.\* | <p>{</p><p>"someField": "a",</p><p>"transactionId": 1000,</p><p>"anotherField": "b",</p><p>"store": "c",</p><p>"clientUniqueId": "12345",</p><p>"items": \["item1", "item2", "item3"],</p><p>"extraField": "d"</p><p>}</p> | <p>{</p><p>"someField": "a",</p><p>"transactionId": 1000,</p><p>"anotherField": "b",</p><p>"shop": "c",</p><p>"clientUniqueId": "12345",</p><p>"items": \["item1", "item2", "item3"],</p><p>"extraField": "d"</p><p>}</p> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloud.hoverfly.io/create-simulations/configuring-request-matchers/json-request-matchers-on-the-body/regular-expression-matcher.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
