Forum Discussion

Puli's avatar
Puli
Icon for Nimbostratus rankNimbostratus
Apr 15, 2011

matching numbers patter in a url

I need to match below patter in a url and re-direct traffic.

 

 

http://www.abc.com/temp/2011/12/temp.html

 

 

Am using below code

 

 

if { [string match {*/*[0-9]*/*[0-9]*/* } [HTTP::uri] } {

 

user pool pool1

 

}

 

 

when run config sync to peer, i get an error saying invalid argument.

 

 

if i escape the special characters like

 

{\*\/\*[0-9]\*\/\*[0-9]\*\/\*} config sync run sucessfully but the url patter does not match.

 

 

Any ideas , am ok not using string match if there's a better alternative.

 

 

thanks.

 

5 Replies

  • Hi Puli,

     

     

    Can you try this:

     

     

    if { [string match "*/*\[0-9\]*/*\[0-9\]*/*" [HTTP::uri] } {

     

     

    Only the square braces should need to be escaped if you wrap the pattern in double quotes instead of curly braces.

     

     

    Aaron
  • Puli's avatar
    Puli
    Icon for Nimbostratus rankNimbostratus
    thanks aaron,

     

    works perfect ! appreciate it.

     

  • Puli's avatar
    Puli
    Icon for Nimbostratus rankNimbostratus
    Small problem facing with the match.

     

    Its also matching

     

    http://www.abc.com/temp/barton2011/12/temp.html

     

     

    How can i make it so it only strictly matches number and ignores letter in it ?

     

     

    thanks.
  • Can you provide a few more examples of URIs you do want to match a few that you don't?

     

     

    Thanks, Aaron
  • Puli's avatar
    Puli
    Icon for Nimbostratus rankNimbostratus
    Hi aaron,

     

     

    i fixed it, i had a wildcard in front that matching all characters followed by numbers. Below is the modified one

     

     

    From

     

    if { [string match "*/*\[0-9\]*/*\[0-9\]*/*" [HTTP::uri] } {

     

    to

     

    if { [string match "*/\[0-9\]*/*\[0-9\]/*" [HTTP::uri] } {

     

     

    I had to match only url of specific type

     

     

    http://www.abc.com/temp/[digits]/[digits]/temp.html

     

     

    thanks for the support.

     

    Appreciate it.