JSFiddle - React, Tailwind, and code Playground
HTML
<div id="results"></div>
JavaScript
var str = "randomnessstuff;morestuff and a semicolon in quotes : \";\";some more stuff",
results = document.getElementById("results");
results.innerHTML = "";
// use regex /(;)(?![";"])/
// match a semicolon (;)
// and also DON'T match (?![value])
// this grouping: ";"
// replace the desired semicolons with bar
results.innerHTML += "<b>Replace</b><br>";
results.innerHTML += str.replace(/(;)(?![";"])/g, '|') + '<br>';
// split the string by the appropriate semicolons
var strArr = str.split(/(;)(?![";"])/);
results.innerHTML += "<b>Split</b><br>";
for (s in strArr) {
if (strArr[s] !== ";") {
results.innerHTML += strArr[s] + '<br>';
}
}