JSFiddle - React, Tailwind, and code Playground

by Swivelgames

HTML

<p contentEditable="true" id="blogbody1">This is some test content! So I'll be editing it here and there. I'd like to put in this random quote, though! :) [quote]This is a really good quote, let me tell you![/quote]Alright, now that I've made this awesome quote, I want to split it from this text area!</p>

CSS

#blogbody1 { border:1px solid #000; padding:5px 8px; }

JavaScript

var haystack = $('#blogbody1').html();
var matches = haystack.match(/\[([A-Za-z]*)\](.*?)\[\/\1\]/is);
var pos = haystack.indexOf(matches[0]);
var snippets = new Array();
    snippets[0] = haystack.substr(0,pos);
    snippets[1] = matches[2];
    snippets[2] = haystack.substr(pos+matches[0].length);
console.log(snippets);
console.log(matches);
console.log(pos);
if(pos+matches[0].length>=haystack.length) console.log('At End Of Post');