Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Between Markers by flairplaya
"use strict";
function betweenMarkers(txt, beg, end) {
var b = txt.includes(beg) ? txt.indexOf(beg) + beg.length : 0;
var e = txt.includes(end) ? txt.indexOf(end) : txt.length;
return txt.slice(b, e);
}
var assert = require('assert');
if (!global.is_checking) {
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!");
}
July 1, 2018