Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Using split with regex
Old 09-01-2008, 07:36 AM Using split with regex
vividearth's Avatar
Experienced Talker

Posts: 33
Location: London, UK
Trades: 0
Hi I am trying to break up a string in the form:

test1 test2 "test3 test4" test5 'test6 test7' test8

into an array in the form:

tags[0] = test1
tags[1] = test2
tags[2] = test3 test4
tags[3] = test5
tags[4] = test6 test7
tags[5] = test8

I am using the regex /'([^']*)'|"([^"]*)"|([^\s| ]+)/

If i run this through expresso it gives me the correct results but in javascript using the split method:

var test = "test1 test2 \"test3 test4\" test5 'test6 test7' test8";
var tags = test.split(/'([^']*)'|"([^"]*)"|([^\s| ]+)/);

I get no results!

Any ideas what I am doing wrong?

Thanks
v
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
vividearth is offline
Reply With Quote
View Public Profile Visit vividearth's homepage!
 
 
Register now for full access!
Old 09-01-2008, 09:54 AM Re: Using split with regex
vividearth's Avatar
Experienced Talker

Posts: 33
Location: London, UK
Trades: 0
Cracked it:

var test = "test1 test2 \"test3 test4\" test5 'test6 test7' test8";
var re = new RegExp(/'([^']*)'|"([^"]*)"|([^\s| ]+)/g);
var m = test.match(re);

if anyone interested.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
vividearth is offline
Reply With Quote
View Public Profile Visit vividearth's homepage!
 
Reply     « Reply to Using split with regex
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09815 seconds with 12 queries