Menu
Scroll for more
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Open source
findBetween(content, left, right, [repeat])
Function that returns a string from between two other strings.
| Parameter | Type | Description |
|---|---|---|
| content | string | The string to search through (e.g. Response.body) |
| left | string | The string immediately before the value to be extracted |
| right | string | The string immediately after the value to be extracted |
| repeat (optional) | boolean | If true, the result will be a string array containing all occurrences |
Returns
| Type | Description |
|---|---|
| string | The extracted string, or an empty string if no match was found. If repeat=true, this will be an array of strings or an empty array |
Example
JavaScript
JavaScript
import { findBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
export default function () {
const response = '<div class="message">Message 1</div><div class="message">Message 2</div>';
const message = findBetween(response, '<div class="message">', '</div>');
console.log(message); // Message 1
const allMessages = findBetween(response, '<div class="message">', '</div>', true);
console.log(allMessages.length); // 2
}Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.