#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    456
    Rep Power
    15
    Hi, I have a string like:
    64.52.26.230:6355,103359,26905,97.28

    I want to cut this down to:
    64.52.26.230:6355

    Basically I want to take all characters up to the first comma and assign this new string to a variable called $server. Can anyone tell me how to do this?

    [This message has been edited by scream (edited August 25, 2000).]
  2. #2
  3. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $var =~ /^([^,]+)/;
    $server = $1;
    [/code]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    456
    Rep Power
    15
    I have been working on this regular expression and come up with this:


    $server = "64.52.26.230:6355,103359,26905,97.28";
    if ($server =~ /.*?,/) {
    print "worksn";
    }


    I guess my regex is /.*?,/ which matches everything up to the first comma. How do I take this regex and make it assign everything up the the first comma to a variable?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    456
    Rep Power
    15
    Thanks, I ended up with

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $var = "64.52.26.230:6355,103359,26905,97.28";
    $var =~ /^([^,]+)/;
    $server = $1;
    print "$servern";
    [/code]

IMN logo majestic logo threadwatch logo seochat tools logo