You can configure match and replace rules to automatically replace parts of messages as they pass through the proxy. To create a rule, go to the Proxy > Match and replace tab and click Add. The Add match/replace rule window opens, which has two modes:
On the Settings mode tab, you can add match and replace rules using the configuration options. Each match and replace rule specifies a literal string or regex pattern to match, and a string to replace it with.
You can use this to create rules for both HTTP and WebSocket messages.
To add a new rule using Settings mode:
Specify the details of the match/replace rule:
The new rule is added to the table and automatically enabled for the current project.
You can use a regex pattern to match the text you want to replace. This enables you to match a variety of text inputs that follow a specific format, such as email addresses or IP addresses. It also enables you to match the underlying structure for content that changes dynamically.
You can use regex syntax to match multi-line regions of a message body. For example, if a response body contains only:
Now is the time for all good men
to come to the aid of the partythen using the regex:
Now.*thewill match:
Now is the time for all good men
to come to the aid of theIf you want to match only within a single line, you can modify the regex to:
Now[^\n]*thewhich will match:
Now is the
In a Match expression you can:
For example, to match a pair of opening and closing tags with no other tags between, you could use the regex:
<([^/]\w*)[^>]*>[^>]*?</\1[^>]*>You can reference groups in the replacement string by using a $ followed by the group index. For example, the following replacement string would include the name of the tag that matched the above regex:
Replaced: $1
Script mode enables you to apply Java-based scripts to define powerful HTTP match and replace rules. For more information, see Creating HTTP match and replace rules using scripts.