<html>
<head>
<title>Javascript RegEx Multiline - RJM Programming - February, 2019 ... thanks to https://stackoverflow.com/questions/49209362/what-is-the-meaning-of-s-s-gm-in-javascript and https://www.w3schools.com/jsref/met_document_execcommand.asp</title>
<script type='text/javascript'>
var rest='';
function cthen() {
if (rest != '') {
eval('' + rest);
rest='';
}
}
function bthen(invlo) {
var invls=invlo.value.split(';');
if (eval('' + invls.length) > 1) {
rest=invlo.value.replace(invls[0] + ';', '');
if (rest.trim() == '') {
rest='';
} else {
rest=rest.replace(/this\./g, "document.getElementById('" + invlo.id + "').");
setTimeout(cthen, 200);
}
}
return invlo;
}
function bold_all(ibut) {
document.designMode="on";
document.execCommand(ibut.value.toLowerCase(),true,('' + ibut.title));
}
function myTrimNonMultiline(x) {
var xx="";
eval("xx=x" + bthen(document.getElementById('itwo')).value.split(';')[0]);
if (rest.replace(/\ /g,'').indexOf('x=') != -1) {
eval(rest.replace(/\ \=/g,'=').replace(/\=\ /g,'=').replace(/x\=/g,'xx=').replace(/\=x/g,'=xx'));
}
return xx; //x.replace(/^\s+|\s+$/g,'');
}
function myTrim(x) {
var xx="";
eval("xx=x" + bthen(document.getElementById('ione')).value.split(';')[0]);
if (rest.replace(/\ /g,'').indexOf('x=') != -1) {
eval(rest.replace(/\ \=/g,'=').replace(/\=\ /g,'=').replace(/x\=/g,'xx=').replace(/\=x/g,'=xx'));
}
return xx; //x.replace(/^\s+|\s+$/gm,'');
}
function myTrimNonMultilineDiv(x) {
var xx='';
eval("xx=x.replace(/\<br\>/gm,String.fromCharCode(10))" + bthen(document.getElementById('itwo')).value.split(';')[0] + ".replace(/\ \;/g,' ')" + bthen(document.getElementById('itwo')).value.split(';')[0] + ".replace(/\ /g,' ')");
if (rest.replace(/\ /g,'').indexOf('x=') != -1) {
eval(rest.replace(/\ \=/g,'=').replace(/\=\ /g,'=').replace(/x\=/g,'xx=').replace(/\=x/g,'=xx'));
}
while (xx.indexOf(String.fromCharCode(10)) != -1) {
xx=xx.replace(String.fromCharCode(10),'<br>');
}
return xx;
}
function myTrimDiv(x) {
var xx="";
eval("xx=x.replace(/\<br\>/gm,String.fromCharCode(10)).replace(/\ \;/g,' ')" + bthen(document.getElementById('ione')).value.split(';')[0].split(';')[0] + ".replace(/\ /g,' ')");
if (rest.replace(/\ /g,'').indexOf('x=') != -1) {
eval(rest.replace(/\ \=/g,'=').replace(/\=\ /g,'=').replace(/x\=/g,'xx=').replace(/\=x/g,'=xx'));
}
while (xx.indexOf(String.fromCharCode(10)) != -1) {
xx=xx.replace(String.fromCharCode(10),'<br>');
}
return xx;
}
function populate(tao, taotwo) {
var tva=tao.value;
while (tva.indexOf(String.fromCharCode(10)) != -1) {
tva=tva.replace(String.fromCharCode(10),'<br>')
}
while (tva.indexOf(' ') != -1) {
tva=tva.replace(' ', ' ')
}
document.getElementById('regexm').value=myTrim(tao.value);
document.getElementById('regexnonm').value=myTrimNonMultiline(tao.value);
document.getElementById('dbasis').innerHTML=tva;
document.getElementById('dregexm').innerHTML=myTrimDiv(tva);
document.getElementById('dregexnonm').innerHTML=myTrimNonMultilineDiv(tva);
if (taotwo) {
if (taotwo.value.indexOf(String.fromCharCode(10)) != -1) {
taotwo.rows='' + eval('' + taotwo.value.split(String.fromCharCode(10)).length);
}
}
}
function dpopulate(tao, taotwo) {
var tva=tao.innerHTML;
while (tva.indexOf('<br>') != -1) {
tva=tva.replace('<br>', String.fromCharCode(10))
}
while (tva.indexOf(' ') != -1) {
tva=tva.replace(' ', ' ')
}
document.getElementById('regexm').value=myTrim(tva);
document.getElementById('regexnonm').value=myTrimNonMultiline(tva);
document.getElementById('basis').value=tva;
document.getElementById('dbasis').innerHTML=tao.innerHTML.replace(/\ /g,' ');
document.getElementById('dregexm').innerHTML=myTrimDiv(tao.innerHTML);
document.getElementById('dregexnonm').innerHTML=myTrimNonMultilineDiv(tao.innerHTML);
//alert(tao.innerHTML);
if (taotwo) {
if (taotwo.value.indexOf(String.fromCharCode(10)) != -1) {
taotwo.rows='' + eval('' + taotwo.value.split(String.fromCharCode(10)).length);
}
}
}
function tatodiv(tv) {
if (tv != '') {
//document.getElementById('trdiv').innerHTML=document.getElementById('trdiv').innerHTML.replace(/\ /g,' ');
//alert(document.getElementById('trdiv').innerHTML);
document.getElementById('trdiv').style.display='table-row';
document.getElementById('trta').style.display='none';
document.getElementById('dbasis').setAttribute('contenteditable',true);
} else {
document.getElementById('trta').style.display='table-row';
document.getElementById('trdiv').style.display='none';
}
}
</script>
</head>
<body id=mybody title="HTML object is document.getElementById('mybody') and the contents is document.getElementById('mybody').innerHTML" onload="populate(document.getElementById('basis'),null); dpopulate(document.getElementById('dbasis'),null);">
<h1 id=myh1 title="HTML object is document.getElementById('myh1') and the wording is document.getElementById('myh1').innerHTML">Javascript RegExp Multiline</h1>
<h3 id=myh3 title="HTML object is document.getElementById('myh3') and the wording is document.getElementById('myh3').innerHTML">RJM Programming - February, 2019</h3>
<table id=mytable title="HTML object is document.getElementById('mytable') and its contents is document.getElementById('mytable').innerHTML"><tr><th id=mythtwo title="HTML object is document.getElementById('mythtwo') and the content is document.getElementById('mythtwo').innerHTML">Selection Toggle of <select id=myselect title="HTML object is document.getElementById('myselect') and the wording is document.getElementById('myselect').innerHTML" onchange=tatodiv(this);><option value=''>above</option><option value='below'>above or below</option></select> ...</th><th><input id=bbold title="HTML object is document.getElementById('bbold') and the wording is document.getElementById('bbold').value" type=button onclick="bold_all(this);" value="Bold"></input></th><th><input id=bst title="HTML object is document.getElementById('bst') and the wording is document.getElementById('bst').value" type=button onclick="bold_all(this);" value="StrikeThrough"></input></th><th><input id=bsubs title="HTML object is document.getElementById('bsubs') and the wording is document.getElementById('bsubs').value" type=button onclick="bold_all(this);" value="SubScript"></input></th><th><input id=bsups title="HTML object is document.getElementById('bsups') and the wording is document.getElementById('bsups').value" type=button onclick="bold_all(this);" value="SuperScript"></input></th><th><input id=bbc title="HTML object is document.getElementById('bbc') and the wording is document.getElementById('bbc').value" type=button onclick="bold_all(this);" title="olive" value="BackColor"></input></th><th><input id=bfc title="HTML object is document.getElementById('bfc') and the wording is document.getElementById('bfc').value" type=button onclick="bold_all(this);" title="red" value="ForeColor"></input></th><th><input id=bihr title="HTML object is document.getElementById('bihr') and the wording is document.getElementById('bihr').value" type=button onclick="bold_all(this);" value="InsertHorizontalRule"></input></th><th><input id=bit title="HTML object is document.getElementById('bit') and the wording is document.getElementById('bit').value" type=button onclick="bold_all(this);" title="🔤" value="InsertText"></input></th><th><input id=bfs title="HTML object is document.getElementById('bfs') and the wording is document.getElementById('bfs').value" type=button onclick="bold_all(this);" title="32px" value="FontSize"></input></th><th><input id=bfn title="HTML object is document.getElementById('bfn') and the wording is document.getElementById('bfn').value" type=button onclick="bold_all(this);" title="Verdana" value="FontName"></input></th><th><input id=bip title="HTML object is document.getElementById('bip') and the wording is document.getElementById('bip').value" type=button onclick="bold_all(this);" value="InsertParagraph"></input></th><th><input id=bilb title="HTML object is document.getElementById('bilb') and the wording is document.getElementById('bilb').value" type=button onclick="bold_all(this);" value="InsertLineBreak"></input></th><th><input id=bcl title="HTML object is document.getElementById('bcl') and the wording is document.getElementById('bcl').value" type=button onclick="bold_all(this);" title="http://www.rjmprogramming.com.au" value="CreateLink"></input></th></tr></table><br>
<table style="width:100%;" border=50>
<tr><th id=myth1 title="HTML object is document.getElementById('myth1') and the wording is document.getElementById('myth1').innerHTML">Edit This (to var<font size=1>iable</font> x) ...</th><th>Effect of RegExp Multiline ...<br><span style="vertical-align:top;">x</span><textarea rows=1 onblur="populate(document.getElementById('basis'),this);" title="You can change me (and stuff after ; will be processed)" style="width:93%;border:0px solid white;" id=ione value=".replace(/^\s+|\s+$/gm,'')" placeholder=".replace(/^\s+|\s+$/gm,'')">.replace(/^\s+|\s+$/gm,'')</textarea></th><th>Effect of RegExp no Multiline ...<br><span style="vertical-align:top;">x</span><textarea rows=1 onblur="populate(document.getElementById('basis'),this);" title="You can change me (and stuff after ; will be processed)" style="width:93%;border:0px solid white;" id=itwo value=".replace(/^\s+|\s+$/g,'')" placeholder=".replace(/^\s+|\s+$/g,'')">.replace(/^\s+|\s+$/g,'')</textarea></th></tr>
<tr id=trta><td><textarea title="HTML object is document.getElementById('basis') and the wording is document.getElementById('basis'),value" style="height:400px;width:100%;background-color:yellow;" onblur=populate(this,null); id=basis>
The rain
In Spain
Falls mainly
On the plain </textarea><td><textarea title="HTML object is document.getElementById('regexm') and the wording is document.getElementById('regexm'),value" style="height:400px;width:100%;" id=regexm></textarea></td><td><textarea title="HTML object is document.getElementById('regexnonm') and the wording is document.getElementById('regexnonm'),value" style="height:400px;width:100%;" id=regexnonm></textarea></td>
</tr>
<tr id=trdiv style=display:none;><td><div title="HTML object is document.getElementById('dbasis') and the wording is document.getElementById('dbasis').innerHTML" contenteditable=true style="height:400px;width:100%;background-color:yellow;" onblur=dpopulate(this,null); id=dbasis>
The rain
In Spain
Falls mainly
On the plain </div><td><div style="height:400px;width:100%;" id=dregexm></div></td><td><div title="HTML object is document.getElementById('dregexnonm') and the wording is document.getElementById('dregexnonm').innerHTML" style="height:400px;width:100%;" id=dregexnonm></div></td>
</tr>
</table>
</body>
</html>