Forum Discussion

Francois_LAGANT's avatar
Francois_LAGANT
Icon for Nimbostratus rankNimbostratus
Apr 05, 2013

problem with string map and regex

Hello,

 

 

I have a problem of syntax to write the string map operation with regex.

 

 

I am trying to delete a parameter toto=[0-9]&

 

url: http://1.1.1.1/index.php?param=1&toto=5&tata=no

 

 

I want the following result:: http://1.1.1.1/index.php?param=1&tata=no

 

 

So I use:

 

HTTP::uri [string map {toto=[0-9]& ""} [HTTP::uri]]

 

 

But it doesn't work

 

When i use this :

 

HTTP::uri [string map {toto=5& ""} [HTTP::uri]]

 

it works.

 

 

Could you help me please ?

 

1 Reply

  • Here are two methods:

     

     

    Method 1 (string map):

     

    set uri [string tolower [HTTP::uri]]

     

    set totonum [findstr $uri "toto=" 5 "&"]

     

    set test "set newuri \[string map \{toto=$totonum& \"\"\} $uri\]"

     

    eval $test

     

    log local0. "newuri1: $newuri"

     

     

    Method 2 (regsub):

     

    if { [regsub -nocase "toto=\[0-9\]&" $uri "" newuri2] } {

     

    log local0. "newuri2: $newuri2"

     

    }