This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Regular Expressions

Astaro v6.312

http://[1|2|3|4|5|6|7|8|9]
http://[1|2|3|4|5|6|7|8|9]/

Please shed a little light on the two regular expressions above.

With expression #1 above, access to websites by IP are blocked.
With expression #2 above, access to websites by IP are _not_ blocked.

What does the trailing "/" do that screws up the expression?

Confused..


This thread was automatically locked due to age.
Parents
  • Anything within []'s represents only one character so that expression only tests the first character following 'http://', which really isn't a correct test for an IP based address.


    A better expression for testing for an IP based http address would be:

    http://(\d+)(\.\d+){3}/


    1 - 'http://', which is a literal match
    2 - (\d+), group of 1 or more digits
    3 - (\.\d+){3}, dot & group of 1 or more digits, repeated 3 times
    4 - /, which is a literal match

    Possibly make sure its at the beginning of the string only:

    ^(http://(\d+)(\.\d+){3}/)


    To add in https:

    ^(http(s?)://(\d+)(\.\d+){3}/)



    I hope this helps you.
  • An example of what your expression would catch that the one I use would not would be useful.

    I am really only trying to stop access to sites by IP address, not sites that may have a number in them.

    The expression http://[1|2|3|4|5|6|7|8|9] is currently stopping access to sites by IP address for me.  

    I was just wondering why putting a / after it made it stop working.  Maybe because it was expecting another character to follow?  I don't know.
Reply
  • An example of what your expression would catch that the one I use would not would be useful.

    I am really only trying to stop access to sites by IP address, not sites that may have a number in them.

    The expression http://[1|2|3|4|5|6|7|8|9] is currently stopping access to sites by IP address for me.  

    I was just wondering why putting a / after it made it stop working.  Maybe because it was expecting another character to follow?  I don't know.
Children
  • The expression you use only checks one character following any http:// it finds in the string for numbers 1 thru 9, when you add the trailing / you are now telling it to match something like the following:


     http://1/
       or
     http://9/


    The reason I say its not a good expression (the one you are using) is because while it will match IP http sites it will also match sites/queries like:

    1-st-pop-up-menu-builder.com
    
    www.somedomain.com/webstats.php



    Simply put the expressions I provided in my previous post do exactly what you are after which is only sites using an IP styled address. The only exception is that the first expression example could match anywhere in the string passed to it which is very possible.
  • Thanks.  I will swap the expressions out and see what happens.

    Very good explanation, I appreciate it.