Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Between Markers by andoreyrich
import assert from "assert";
function betweenMarkers(text, begin, end){
const beg = text.indexOf(begin) < 0 ? 0 : text.indexOf(begin) + begin.length
const fin = text.indexOf(end) < 0 ? text.length : text.indexOf(end);
return text.slice( beg, fin);
}
console.log('Example:')
console.log(betweenMarkers('What is >apple<', '>', '<'), 'apple')
assert.equal(betweenMarkers('What is >apple<', '>', '<'), 'apple')
assert.equal(betweenMarkers("My new site",
"", ""), 'My new site')
assert.equal(betweenMarkers('No[/b] hi', '[b]', '[/b]'), 'No')
assert.equal(betweenMarkers('No [b]hi', '[b]', '[/b]'), 'hi')
assert.equal(betweenMarkers('No hi', '[b]', '[/b]'), 'No hi')
assert.equal(betweenMarkers('No ', '>', '<'), '')
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
May 1, 2020