I'm coding a custom markdown parser that should preprocess user input so that each line of the input that starts with three ticks should have the reference code trimmed and all it's spaces replaced with underscores. So in this fiddle
var e = document.getElementById("thetext");
var feedback = document.getElementById("feedback");
var sorted = function(haystack) {
var re = /$```\s*(\S+)(\s+)(\S+)\s*$/g;
return haystack.replace(re, '```$1_$3');
};
e.addEventListener("blur", function(event) {
feedback.innerHTML = sorted(e.value);
}, true);
textarea { width: 400px; height: 400px;}
<textarea id="thetext">
A custom block code marker with reference:
``` John 3:16
For God so loved the world
```
another one with two spaces to be replaced:
```1 Cor 2:15-45
Some other marked up text followed by white space
```
</textarea>
<pre id="feedback">Tab out to see result</pre>
the output should be exactly like the input except for these two lines:
```John_3:16
and
```1_Cor_2:15-45