JSFiddle - React, Tailwind, and code Playground

by lenny86

JavaScript

const [test1, test2, test3, test4] = ["What is >apple<", "<head><title>My new site</title></head>", "No[/b] hi", ">apple<"];
//let regMatch = /(?<=[$-/:-?{-~!"^_`\[\]]).+?(?=[$-/:-?{-~!"^_`\[\]])/

function betweenMarkers(text, begin, end) {
		let regMatch = /(?<=[${begin}]).+?(?=[${end}])/;
    return text.match(regMatch) ? text.match(regMatch)[0] : ''
}

console.log('***************************** TEST 1 *****************************')
console.log(' ')
console.log(betweenMarkers(test1,'>','<'));
console.log('***************************** TEST 2 *****************************')
console.log(' ')
console.log(betweenMarkers(test2,'[', ']'));
console.log('***************************** TEST 3 *****************************')
console.log(' ')
console.log(betweenMarkers(test3,'>','<'));
console.log('***************************** TEST 4 *****************************')
console.log(' ')
console.log(betweenMarkers(test4,'>','<'));
console.log(' ')
console.log(' ')