473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

preg_match type split

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'
TIA

Mar 5 '07 #1
3 3930
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?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 5 '07 #2
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)
Mar 5 '07 #3
On 5 Mar, 12:17, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
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;">capt...@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]= 'capt...@starshipenterprise.com'

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.

Mar 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: fartsniff | last post by:
hello all, here is a preg_match routine that i am using. basically, $image is set in some code above, and it can be either st-1.gif or sb-1.gif (actually it randomly picks them from about 100...
5
by: Mark Woodward | last post by:
Hi all, I'm trying to validate text in a HTML input field. How do I *allow* a single quote? // catch any nasty characters (eg !@#$%^&*()/\) $match = '/^+$/'; $valid_srch = preg_match($match,...
6
by: mantrid | last post by:
Hello Found this piece of code using preg_match to check file types during upload of files. $allowed_file_types = "(jpg|jpeg|gif|bmp|png)"; preg_match("/\." . $allowed_file_types . "$/i",...
7
by: Chuck Anderson | last post by:
I am trying to implement email injection protection by looking for \r and/or \n in the name, subject, or email address fields from my contact form The first script, contact_us.php, contains a...
0
by: xmanofsteel69 | last post by:
I'm trying to create a search function for my site and I can't ever seem to figure it out. If anybody could help, that would be awesome, because everything I try, I keep getting errors... Here's...
3
by: Henri | last post by:
Hello, I am trying to split a string that contains parentheses; the aim here is to keep the part that's before the opening parenthese: the string (quoted here) is "36 (72 cm)" First I want to...
2
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
8
by: Thomas Mlynarczyk | last post by:
Hello, I want to split a given string into tokens which are defined by regexes: // example tokens - a bit more complex in real $tokens = array( 'NUMBER' ='~^\d+~', 'NAME' ='~^+~', 'ANY' ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.