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

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Question Want to grab hostname out of filename?


    I want to be able to parse out the HOSTNAME of this example below, any help would be appreciated I am learning regex as I go. It is for scripting no particular language:

    filename.08ad562.HOSTNAME-2012.08.02.13.50
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    HOSTNAME is the only part that is between a period and a hyphen?
    Code:
    (?<=\.)[^-]+
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0
    Did not work it gave me this:

    838a8dad.v210
    08.02.13.50

    Here is the an actual filename: explorer.838a8dad.v210-2012.08.02.13.50

    In this example I only want v210 which is the hostname but hostnames will vary
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    Hmm, yes it would do that...
    Code:
    (?<=\.)[^.-]+
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0
    Unfortunately is doesn't, I tested it via RegExRX on my Mac but this site also shows same thing: on regex planet
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    ...Where's the lookahead? Why isn't the lookahead in there?
    Code:
    (?<=\.)[^.-]+(?=-)
    I'm surprisingly off the ball today. Time for a lunch break.

    Comments on this post

    • ManiacDan agrees : This was pretty bad
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0
    Sweet that worked, thanks now I can continue what I was doing, So it was a look behind, not character in set one or more times, and look ahead. Thanks thats awesome!

IMN logo majestic logo threadwatch logo seochat tools logo