Forum Discussion
Shuki_griba_304
Nimbostratus
Feb 10, 2017Regexp as string - dynmic
Hello,
I need help about Regexp.
The [HTTP::payload] at HTTP_REQUEST_DATA is dynamic. i made a procedure that build the regexp.
i don't know how to write the "if" Sentence.
The procedure:
set Rege...
StephanManthey
Nacreous
Feb 13, 2017Hi Shuki,
the comparison by match_regex works exactly the way you described it. Its probably just the pattern, which makes it fail. Using your example the following iRule returns the expected result:set RegexStr "\["
set Body [HTTP::payload] ; >>> [11,222,333,4444]
set Body [string range $Body 1 end-1]
set Body [string map {"," " "} $Body]
set ItemCount [llength $Body]
for {set x 0} {$x < $ItemCount} {incr x} {
set Item [lindex $Body $x]
set ItemLength [string length $Item]
append RegexStr "(\\d{$ItemLength}),"
}
replacing the trailing comma by a closing bracket
regsub {,$} $RegexStr "\]" RegexStr
regex match
if { [HTTP::payload] matches_regex $RegexStr } { log "[HTTP::payload] matching regex ($RegexStr)" }
Sending a request by using cURL as follows results in the log message shown below:
curl -v 'http://10.131.131.111/test' --data '[11,222,3333,44444]'
: [11,222,3333,44444] matching regex (\[(\d{2}),(\d{3}),(\d{4}),(\d{5})])
Thanks, Stephan
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
