Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
between_markers solution in Clear category for Between Markers by Jon_Red
import assert from'assert';
function betweenMarkers(text:string,begin:string,end:string):string{
return text.slice(
text.includes(begin)?text.indexOf(begin)+begin.length:0,
text.includes(end)?text.indexOf(end):text.length
);
}
// self-checks
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 ','>','<'),'');
July 20, 2020
Comments: