Forum Discussion

Carl_Weiss_1340's avatar
Carl_Weiss_1340
Icon for Nimbostratus rankNimbostratus
Jun 28, 2016
Solved

String Scan question ... trying to do something really simple

Its just not working...   Given a string - "/part1/part2/part3/part4" I want the result to be: p1 = part1 p2 = part2 p3 = /part3/part4   which led me to write the following:   when HTTP_REQU...
  • Vernon_97235's avatar
    Jun 28, 2016

    String matchers are "greedy", so %s will match everything up to the next whitespace. That's why /%s/%s/%s won't work; everything ends up in $part1.

    The second construct should work. Indeed, on 11.5.4, I do the following:

    when CLIENT_ACCEPTED {
        set path "/foo/bar/baz/bing"
        
        set x [scan $path {/%[^/]/%[^/]/%s} part1 part2 part3]
        if { $x == 3 } {
            log local0. "part1 = $part1; part2 = $part2; part3 = $part3"
        }
        else {
            log local0. "scan returned ($x) elements"
        }
    }
    

    And it works as I expect. In the logs, I get:

    Jun 27 19:00:01 b201 info tmm[13446]: Rule /Common/test_scan : part1 = foo; part2 = bar; part3 = baz/bing