JSFiddle - React, Tailwind, and code Playground
by dru_zod
HTML
<textarea id="text" cols="50" rows="10">
test http://google.com test
http://porism.com
(http://porism.com)
test (http://porism.com) test
test [http://porism.com] test
test [http://porism.com. test
</textarea>
<input type="button" value="go" id="go" />
<div id="output">
</div>
JavaScript
'regex to find links'
$(function () {
var toHtml = function (text) {
var r = /\bhttp:\/\/[^\s]+/gi;
text = text.replace(r, 'REPLACEMENT');
text = text.replace(/\n/g, '<br />');
return text;
};
$('#go').on('click', function () {
$('#output').html(toHtml($('#text').val()));
});
$('#output').html(toHtml($('#text').val()));
});