...

View Full Version : Need some help with regexp and JS.



marko2511
12-22-2006, 01:15 PM
Hi all!

This is situation:


var data='test: X: 123 Y: 555.666';
var nums=data.match(/[0-9]+\.{0,1}[0-9]*/g);


//results are:
//nums[0]='123';
//nums[1]='555.666';

//but, if data is like this
var data='test: X: 123 Y: 444.555.666';

//results are:
//nums[0]='123';
//nums[1]='444.555';

Basically, I need regexp that will return array with 2 members,
first member with numbers for X and second member with numbers for Y.

Any help?

Arty Effem
12-22-2006, 05:35 PM
[QUOTE=marko2511;516869]Hi all!

This is situation:


var data='test: X: 123 Y: 555.666';
var nums=data.match(/[0-9]+\.{0,1}[0-9]*/g);


//results are:
//nums[0]='123';
//nums[1]='555.666';

//but, if data is like this
var data='test: X: 123 Y: 444.555.666';

//results are:
//nums[0]='123';
//nums[1]='444.555';


Try: /(\d+\.)*\d+/g

marko2511
12-22-2006, 06:25 PM
Try: /(\d+\.)*\d+/g
Thank you, that's it.
:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum