Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/v0.48.x/javascript-api/jslib/utils/findbetween.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/v0.48.x/javascript-api/jslib/utils/findbetween/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
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
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

