JSFiddle - React, Tailwind, and code Playground

by Nicolas PUJOL

JavaScript

/*SUBSTR*/
var str = "Bien le bonjour $texte a extraire$ comment allez-vous ?";

var firstIndex = str.indexOf("$");
var lastIndex = str.lastIndexOf("$");
str = str.substr(firstIndex + 1, lastIndex - firstIndex - 1);

console.log("Substr : ", str);

/*REGEX*/
var str = "Bien le bonjour $texte a extraire$ comment allez-vous ?";

var matches = str.match(/\$(.*)\$/);

console.log("Regex : ", matches[1]);