Forum Discussion

shishir_sontakk's avatar
shishir_sontakk
Icon for Nimbostratus rankNimbostratus
Feb 01, 2019

Strip URI word between first two "/"

Hello, I am looking to see how to strip a word between first two "/" in URI?

 

Example:

 

I would like to strip "abc" and store in some variable which can be used for sending traffic to different pool. Any help/direction/suggestion is appreciated. Thank you.

 

3 Replies

  • I am not sure if I understood by output values. Let me explain more what I am trying to do.

     

    I want to extract word which is between first two "/" in URI and modify the "Host" in the header with extracted word.

     

    Example:

     

    Extract "abc" and use that in header Host as ";.

     

    This "abc" word will be dynamic for different apps so I was thinking to store in variable ( using set) but not sure how I can extract that word.

     

    Thank you.

     

  • You can use getfield to return a specific part of the URI like this:

    set var [getfield [HTTP::uri] "/" 2] 
    This will return abc in your case 
    

    Or if you want to strip out/modify specific parts if the URI, you can use the split command to return a list of elements like this:

    set elements [split [HTTP::uri] "/"]
    set e1 [lindex $elements 0]
    set e2 [lindex $elements 1]
    set e3 [lindex $elements 2]
    set e4 [lindex $elements 3]
    In your case e1 would be empty, e2 would be abc, e3 would be garbage, and e4 would be moregarbage
    

    If you have any more questions, I am sure I can help