Forum Discussion
regex for a number between 1-99
Hi There,
I am trying to validate a string with that is like this:
pw-10:1000.100
The regex i am using is:
^pw-[1-9]\d?
This works in perl, and infact in tcl 8.5 but doesnt match in the irule for some reason.
the tcl i am using to see if it work is:
set string "12 Again and again and again ..."
if { [regexp {(^[1-9]\d?)} $string => digits] } {
puts "we got $digits in string"
} else {
puts "nothing here"
}
The irule is like this:
switch -regex $string {
"^pw-[1-9]\d?:" {
do some stuff
}
default {
}
There is more of course but you get the idea.
Any ideas?
Paul
3 Replies
- paul_73820
Nimbostratus
I think i see the issue.
i wasnt separating ?: so it fails.
Doing ^pw-([1-9]\d?): works fine. - hoolio
Cirrostratus
Hi Paul,
If you can use a string or scan command it should be more efficient than regexp:switch -glog $str { pw-[1-9]* - }
Note that I didn't check for the optional digit following 1-9 as you had it listed as optional in your regex.
Aaron - paul_73820
Nimbostratus
Thanks hoolio,
I think you mean glob ;)
If you use glob is it a string match?
I was using regex as we had a number of tricky strings that were evaluated in the same switch, thats not the case now so might be time to review and drop the regex.
I havent noticed any real impact due to regex yet.
Paul
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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
