Forum Discussion
Robert_47833
Altostratus
Nov 22, 2011how to match 6 digtals via command except matches_regex
hi,dear irule
if {$uri matches_regex {-[0-9][0-9][0-9][0-9][0-9][0-9]}} {
pool xxx
}
I don't wanna use matches_regex any more
do u have an alternation method to achieve this?
thanks in advance.
15 Replies
- nitass
Employee
i'm not quite familiar with glob or regex. hope there is another which is better than this one. 🙂[root@ve1023:Active] config b rule myrule list rule myrule { when RULE_INIT { log local0. "\[string match \[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\] 123456\]: [string match \[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\] 123456]" log local0. "\[string match \[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\] abcdef\]: [string match \[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\] abcdef]" } } [root@ve1023:Active] config cat /var/log/ltm Nov 22 01:14:32 local/ve1023 err mcpd[23057]: 01020066:3: The requested rule (myrule) already exists in partition Common. Nov 22 01:14:32 local/tmm info tmm[24220]: Rule myrule : [string match [0-9][0-9][0-9][0-9][0-9][0-9] 123456]: 1 Nov 22 01:14:32 local/tmm info tmm[24220]: Rule myrule : [string match [0-9][0-9][0-9][0-9][0-9][0-9] abcdef]: 0 - Robert_47833
Altostratus
thanks ,very much
suppose I need to use string to represent many digitals ,I don't know the exact number of this digtals,how to achieve this?
[0-9]*? - hoolio
Cirrostratus
Hi Jucao,
If you need to match any number of digits in an arbitrary position you'll probably need to use a regex. To match one or more digits, you can use [0-9]+ for regex. If you know of a delimiter for the numbers you might be able to use scan or getfield to parse the digits and avoid the high CPU usage of a regex.
Aaron - Robert_47833
Altostratus
hello,Aaron
I know the delimiter ,it is /
suppose the uri is /cjj/xx/1234567777/xyz
I need to check whether the fourth gield is number(s)
how to achieve this?
it is 1234567777 in our case
but the length of this is not certain
it can be 123 or 1234 - Joel_Moses
Nimbostratus
Yep, getfield is great for this:set captured_value [getfield [HTTP::uri] "/" 4]
Will snag the number you're looking for no matter what its length, as long as it's in the same position in the URI each time. No regex needed. - Robert_47833
Altostratus
I WANT TO know whether [getfield [HTTP::uri] "/" 4] are number and are in range [0-9] - Joel_Moses
Nimbostratus
Check my reply in the other thread. You can use "[string match [0-9] [getfield [HTTP::uri] "/" 4]]" to do this. (Okay, that's the all in one line way to do it, but, seriously, check the other thread.) :> - hoolio
Cirrostratus
I think you'd need to list the exact number of digits that you want to match when using string match. If you use scan, you can match on any number of digits using %[0-9]:if {[scan [getfield [HTTP::uri] "/" 4] {%[0-9]} match]==1}{ Parsed all digits } else { Did not parse all digits }
Aaron - Robert_47833
Altostratus
hi,Aaron
u are right
if I want to use string match,I need to list the exact number of digits
so I would like to use scan
but the command u gave is wrong,some sytax error
would u like to give me a correct one
thanks inadvance - Robert_47833
Altostratus
hi,Aaron
I tried your method
see,some case it doesn't work ,if it is :222xyz,it can exclude xyz222,but it conside 222xyz as all digits
really need your help this time
if { [scan [getfield [HTTP::uri] "/" 2] { %[0-9] } match ] == 1 } {
log local0. " [getfield [HTTP::uri] "/" 2] is ok" }
else {
log local0. " [getfield [HTTP::uri] "/" 2] is not ok"
}
Jun 10 11:37:34 slot3/tmm3 info tmm3[8092]: Rule srwd30-www : xyz222 is not ok
Jun 10 11:37:34 slot3/tmm3 info tmm3[8092]: Rule srwd30-www : xyz222 is not ok
Jun 10 11:37:42 slot3/tmm2 info tmm2[8091]: Rule srwd30-www : 222xyz is ok
Jun 10 11:37:42 slot3/tmm2 info tmm2[8091]: Rule srwd30-www : 222xyz is ok
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
