Question : Javascript Regex - reformat texetarea entries?

Thanks to HugoHiasl I have a script (below) that APPENDS textarea contents into a
Select List Box (dynamically). How can I use Javscript Regex to reformat the textarea
items as they are appended to the Select List Box?
 
If the textarea items are formatted like this:
 
  LName1,Fname1,EmailAddress1@something.com;
  LName2,Fname2,EmailAddress2@somethingelse.com;

They should be appended to the Select List Box like this:

  "LName1, Fname1" <[email protected]om>,
  "LName2, Fname2" <EmailAddres2s@somethingelse.com>,
 
Thanks....!

´*•.¸(`*•.¸?¸.•*´)¸.•*´
?«´•°*42DoubleDDs*°•´»?
.¸.•*(¸.•*´?`*•.¸) *•.¸


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
<html>
<body>
<form name="Mainform">
<textarea name="dataentry" rows="5" cols="45">

</textarea>
<input Type="Button" Name="loadbutton" Value="LOAD" onclick="BuildSelect()"><BR><BR>

<select name="dataadded" multiple>
</select>

</form><BR><BR>

<script Language="Javascript">
function BuildSelect(){
      var Options = document.forms[0].dataadded.options;
      var startIndex = Options.length;
  var thearray = document.forms[0].dataentry.value.split(';');
  for (var i=0; i < thearray.length; i++) {
            Options[i+startIndex] = new Option(thearray[i],thearray[i]);
  }
}
</script>
</body>
</html>

Answer : Javascript Regex - reformat texetarea entries?

This works nicely
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
<html>
<body>
<form name="Mainform">
<textarea name="dataentry" rows="5" cols="45">

</textarea>
<input Type="Button" Name="loadbutton" Value="LOAD" onclick="BuildSelect()"><BR><BR>

<select name="dataadded" multiple>
</select>

</form><BR><BR>

<script Language="Javascript">
function BuildSelect(){
  var Options = document.forms[0].dataadded.options;
  var startIndex = Options.length;
  var sourceString = document.forms[0].dataentry.value;
  sourceString = sourceString.replace(/\s*(.*),([^,\n]*);/g, '"$1" <$2>,##splitstringhere##');
  var thearray = sourceString.split('##splitstringhere##');
  for (var i=0; i < thearray.length; i++) {
    if (thearray[i].match(/\S/)) {
      Options[i+startIndex] = new Option(thearray[i],thearray[i]);
    }
  }
}
</script>
</body>
</html>
Random Solutions  
 
programming4us programming4us