No results for

Powered byAlgolia
  • jslib
  • utils
  • findBetween(content, left, right, [repeat])

findBetween(content, left, right, [repeat])

Function that returns a string from between two other strings.

contentstringThe string to search through (e.g. Response.body)
leftstringThe string immediately before the value to be extracted
rightstringThe string immediately after the value to be extracted
repeat (optional)booleanIf true, the result will be a string array containing all occurrences


stringThe 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


import { findBetween } from '';
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