cancel
Showing results for 
Search instead for 
Did you mean: 

Irule with Dynamic Regexp

Oferb
Nimbostratus
Nimbostratus
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 RegexStr "\\\[" set Body [HTTP::payload] ->>>[210,21,33] 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] if {$x < $ItemCount} { append RegexStr "(\\d{$ItemLength})," } else { append RegexStr "(\\d{$ItemLength})\\\]" } }

The Result of this procedure: $RegexStr = "[(d{3}),(\d{2}),(\d{2})]" ---->match the Body

 

I need solution like this "IF":

 

if {$Body matches_regex $RegexStr} { log local0. "Matched" }

 

Thanks

 

6 REPLIES 6

Shuki_griba_304
Nimbostratus
Nimbostratus

I have the same issue. Someone know how to ??? Thanks.

 

Kai_Wilke
MVP
MVP

Hi Oferb,

 

can you please explain the outcome of this function? I didn't get the point of building a RegEx pattern based on certain input data followed by a check if the very same input data matches the created RegEx pattern.

 

Note: The question seems to be a carbon copy of https://tstdmzdevcentral.olympus.f5net.com/questions/regexp-as-string-dynmic-51588. Same user or same problem/requirement?

 

Cheers, Kai

 

Shuki_griba_304
Nimbostratus
Nimbostratus

Hi Kai, Thank you for your response.

 

I will explain, I Recieve this kind of data in the request body;

 

[10] or [43,11] OR [55,65,999]

 

And so on.

 

I need to write a regexp that will match this inputs.

 

Thanks again

 

Kai_Wilke
MVP
MVP

Hi Shuki,

 

This doesn't explain the entire outcome. Once you build the RegEx, what is the purpose of having such pattern?

 

The only reson I see right now, is to check if each segment (while ignoring the total number of segments) of the message contains only digits (while ignoring the total digit lenght), isn't it?

 

Cheers, Kai

 

JRahm
Community Manager
Community Manager

Clarity would be helpful. Once you provide clear guidance on what you are trying to accomplish, I'd recommend you also take a look at scan instead of regex. Just some pointers to give you additional ideas:

 

% set opts [list "\[10\]" "\[43,11\]" "\[55,65,999\]"] {[10]} {[43,11]} {[55,65,999]} % foreach pattern $opts { set num [scan [string trim [string trim $pattern "\["] "\]"] %d,%d,%d x y z] switch $num { 1 { puts Result: \n $x } 2 { puts "$x, $y" } 3 { puts "$x, $y, $z" } } } Result: 10 43, 11 55, 65, 999

Shuki_griba_304
Nimbostratus
Nimbostratus

Hi Jason, Thank you for your response. This is good idea.

 

Thanks again, Shuki