preg_match type split

  • Thread starter Captain Paralytic
  • Start date
C

Captain Paralytic

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;">[email protected]\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]= '(e-mail address removed)'


TIA
 
E

Evertjan.

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;">[email protected]\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]= '(e-mail address removed)'

Yes, there is.

What javascript did you try yet?

Is this a [school] assignment?
 
E

Evertjan.

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;">[email protected]\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]= '(e-mail address removed)'

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;\">[email protected]\\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.replace(/">/,'');

for (i=0;i<elem.length;i++)
document.write("elem["+i+"] = "+elem+"<br>");

</script>
 
C

Captain Paralytic

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;">[email protected]\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]= '(e-mail address removed)'

Yes, there is.

What javascript did you try yet?

Is this a [school] assignment?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)- Hide quoted text -

- Show quoted text -

It's not a school assignment, just a guy who knows php better than JS.

I was hoping there'd be a slick way to parse this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top