JSFiddle - React, Tailwind, and code Playground
HTML
Brought to you by Daniel Cohen Gindi :-)<br /><br />
Fix subtitles, from punctuation in wrong side of sentences - to corrected ones:<br /><br />
<label>Bad RTL subtitles (punctuation in wrong side of sentences):</label><br />
<textarea id="txtIn"></textarea><br /><br />
<label>Proper RTL subtitles:</label><br />
<textarea id="txtOut"></textarea>
CSS
html, body {
margin: 0;
padding: 0;
}
body { padding: 1em; }
textarea {
width: 100%;
height: 5em;
}
JavaScript
txtIn.addEventListener('input', evt => {
let text = evt.currentTarget.value;
let fixed = text.replace(/\n(.*[א-ת].*[-.;:!?])$/gm, '\n$1');
document.getElementById('txtOut').value = fixed;
});