Evertjan. wrote on 05 mrt 2007 in comp.lang.javascript
:
Captain Paralytic wrote on 05 mrt 2007 in comp.lang.javascript:
>I have the following string in a variable:
'\074a href="" onClick="pl_go(64);return false;">James T Kirk\074/
a>',
'\074a href="" onClick="pl_go(64);return false;">thecaptain\074/a>',
'\074a href="" onClick="pl_go(64);return
false;">ca*****@starshipenterprise.com\074/a>'
(there are 3 newlines in there).
Is there a simple (possibly regex?) way to split this out to an array
to end
up like:
elem[0] = 64
elem[1] = 'James T Kirk'
elem[2] = 'thecaptain'
elem[3]= 'ca*****@starshipenterprise.com'
Yes, there is.
What javascript did you try yet?
Is this a [school] assignment?
<script type='text/javascript'>
var elem = [];
var s =
"'\\074a href=\"\" onClick=\"pl_go(64);"+
"return false;\">James T Kirk\\074/a>/n',"+
"'\\074a href=\"\" onClick=\"pl_go(64);"+
"return false;\">thecaptain\\074/a>/n',"+
"'\\074a href=\"\" onClick=\"pl_go(64);"+
"return false;\">ca*****@starshipenterprise.com\\074/a>/n'";
elem[0] = s.match(/pl_go\([^\)]*/)[0].replace(/pl_go\(/,'');
r = s.match(/">([^\\]*)/g);
for (var i=0;i<r.length;i++)
elem[i+1] = r[i].replace(/">/,'');
for (i=0;i<elem.length;i++)
document.write("elem["+i+"] = "+elem[i]+"<br>");
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)