SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Regex split

  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex split

    Hi.
    My goal is get a string
    with only numbers inside (without space)
    ie
    123,124,125,126,127,128

    I tried this
    PHP Code:
    var str=" 123 , 124 , ,  , 125,126 ,127, 128 ";
    var 
    re = /\s*,\s*/;
    alert(str.split(re)); 
    but it doesn't work.

    I know there are other easier way
    but for the sake of it
    Bye.
    Last edited by whisher; Apr 20, 2009 at 08:42.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    str.match(/\d+/g).join(",")

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

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