Forum Discussion

SSHSSH_97332's avatar
Icon for Nimbostratus rankNimbostratus
May 14, 2012

Regular Expression to Force Parameter to be in IP Format

i need to force parameter value to be in IP format : ( 3 digits . 3 digits . 3 digits . 3 digits ) , i found option called regex ( regular expression ) under parameters Tab . How can i define regex to do my target ?



5 Replies

  • nathe's avatar
    Icon for Cirrocumulus rankCirrocumulus






    By putting in this regex expression it will look for a parameter in the format (but not xx.xx.xx.xx or similar) Is that what you're after?



    Also, F5 has a neat regex validator tool (App Security, Options, Tools, RegExp Validator) where you can pop this string in and enter a test string e.g. as an example, and it will tell you whether there's a match or not.



    Hope this helps,


  • Every tool has a slightly different implementation of regex. I haven't tested this on F5 yet, so it might not be quite right, but give it a try. I use it ALOT on other systems.










    If f5 supports perl regexes, you can simplify it with






    The important difference between this and the previous poster's regex is it allows each octet in the ip (the octet is the 0-255 number) to be 1-3 digits. Most systems don't 0-pad the octets into 3 digit numbers, so you need this range.




    This regex isn't perfect. It does not force the numbers to be 0-255 ( would match) but normally that is not a problem. However, you might need a more precise solution, for example, if you're trying to protect a parameter that lacks data validation. It probably is possible to write such a regex (I would try look-aheads), but it would be very complex and difficult for others to understand. I would advise against a regex in such a case.


  • Here is an example of a regex that should work to force the numbers to be between 0 and 255. This is just one octet - you would have to do this 4 times, with \. between each.






    So the full regex would be:






  • Oops. Missed some parenthesis...






    Definitely yuck. :)
  • Thanks All . where i can find guide & examples fro regular expressions ?