HTML and JavaScript for parsing E-mails and URLs

HTML part:
<textarea name="Block2" rows="20" cols="50"></textarea><br />
Enter a regular expression type:
<select name="re" onchange="parseWith()">
  <option value="^\W" selected="selected">Choose an expression</option>
  <option value="[\w\.\-]+@[\w\.\-]+\b">E-mails</option>
  <option value="\w{3,6}:/+[\w.]*">URLs</option>
</select><br />
<form name="outform"><textarea name='result' rows='20' cols='50'></textarea></form>
 
JavaScript part:
function parseWith(){
 var txtI = document.text2.Block2.value;
 var re = document.text2.re.value;
 var use = new RegExp(re,"g"); // RegExp constructor compiles entered value to a JavaScript valid regex
 var txtO = txtI.match(use);
  document.outform.result.value = txtO;
 replaceCommas();
}

function replaceCommas(){
 var txt = document.outform.result.value;
 var re = /,/g;
 var rTxt = txt.replace(re,"\n");
  document.outform.result.value = rTxt;
 var para = document.getElementById("label");
 para.lastChild.nodeValue = "";
 para.lastChild.nodeValue = "paragraph separated values";
}

No comments: