help with iRules Regex scan statement.

I’ve been trying to scan the following URI inorder to extract specific fields. The URI is

/mapper/time_map/datatype/comtype/37.777125/-122.419644/13/1309/3164.json?v=1&degree_buffer=0.002&callback=jQuery1720814429080274308_1339544764657&_=1339544771741

i need a regex for a scan statement that will extract the data fields “comtype”, “37.777125” and “-122.419644”

so far i’ve tried this, but keep getting “variable is not assigned by any conversion specifiers”

set testuri “/mapper/time_map/datatype/comtype/37.777125/-122.419644/13/1309/3164.json?v=1&degree_buffer=0.002&callback=jQuery1720814429080274308_1339544764657&_=1339544771741”

scan $testuri {%[^/]%[^/]%[^/]%[^/]%[^/]%[^?]} one two three four five six seven eight

any suggestions?

Why not just use split and then extract the field via lindex?

% set testuri “/mapper/time_map/datatype/comtype/37.777125/-122.419644/13/1309/3164.json?v=1°ree_buffer=0.002&callback=jQuery1720814429080274308_1339544764657&_=1339544771741”

/mapper/time_map/datatype/comtype/37.777125/-122.419644/13/1309/3164.json?v=1°ree_buffer=0.002&callback=jQuery1720814429080274308_1339544764657&_=1339544771741

% set split [split $testuri /]

{} mapper time_map datatype comtype 37.777125 -122.419644 13 1309 3164.json?v=1°ree_buffer=0.002&callback=jQuery1720814429080274308_1339544764657&_=1339544771741

% puts “[lrange $split 4 6]”

comtype 37.777125 -122.419644

% puts “[lindex $split 4]”

comtype

The scan statement will still work, but it seem it has troubles with the / being the first character, so this will work:

% scan $testuri {/%*[^/]/%*[^/]/%*[^/]/%[^/]/%[^/]/%[^/]} one two three

3

% puts $one

comtype

% puts $two

37.777125

% puts $three

-122.419644

Nice work MiLK_MaN. I think the single scan command should be more efficient than split with lindex, etc.

Aaron

Thank MiLK_MaN this works. Btw what editor/shell are you using the check test the irules?

Just tclsh in a Mint Debian virtual machine on my home ESX server :slight_smile: