Forum Discussion

boneyard's avatar
Apr 25, 2012

getting first part of uri

im looking for a way to only get the first part of an uri

 

 

so in all case i should only get test1

 

 

http://something/test1

 

http://something/test1/

 

http://something/test1/something

 

http://something/test1?value=8

 

 

findstr seems to be an interesting option, but i don't believe it can have several possibilities for the findstr command deliminator, so it terminates on for example / and ?, what would be a way to do this?

 

4 Replies

  • Hi,

     

     

    You can use HTTP::path to parse the path without the query string and then use scan to get the first directory:

     

     

    scan [HTTP::path] {/%[^/.]} dir

     

    log $dir

     

     

    Aaron

     

     

  • Or with better error handling:

    
    if {[scan [HTTP::path] {/%[^/.]} dir] == 1}{
       log local0. "parsed $dir"
    } else {
       log local0. "no dir parsed"
    }
    

    Aaron
  • looks good, just wondering about the {/%[^/.]} part, can i just list multiple chars there i want to cause the value to be put in dir? like it is now, will it terminate on / and . ?
  • i tested this and indeed, multiple chars are possible and it will trigger on any from the list, this does exactly what i need.