SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Fire59's Avatar
    Join Date
    Aug 2003
    Location
    mn
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_match problem

    I have a string "2{6}2{5}2{11}" and i'm breaking it it down to
    2{6}, 2{5}, 2{11} using this
    Code:
    preg_match_all("/([0-9]+\{[0-9]+\})/",$str,$matches);
    then i'm using this to break down 2{6} to 2 , 6. But i'm getting 3 element in my matches array 2{6},2,6.
    Code:
    preg_match("/([0-9]+)[{]{1}([0-9]+)[}]{1}/",$str,$matches);
    Is there a way to do just get the 2,6?

  2. #2
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Raleigh, NC
    Posts
    783
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you just use this on the first one and run each triplet through once instead of 4 times:
    PHP Code:
    preg_match_all("/(([0-9]+)\{([0-9]+)\})/",$str,$matches); 

  3. #3
    SitePoint Addict Fire59's Avatar
    Join Date
    Aug 2003
    Location
    mn
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx,

    that's what i was looking for.


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
  •