Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need some help with regexp and JS.

    Hi all!

    This is situation:
    Code:
    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?

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    [QUOTE=marko2511;516869]Hi all!

    This is situation:
    Code:
    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

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by Arty Effem View Post
    Try: /(\d+\.)*\d+/g
    Thank you, that's it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •