RegEx Help

Discussion in 'General Scripting Chat' started by Crazy, Feb 25, 2011.

  1. Crazy

    Crazy Power Member

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    I know nothing about RegEx, but this should be fairly simplistic for anyone with a little experience. I need to match a set of IP ranges. Please PM me if you can help, I'll toss you some $ for your time.
     
  2. chris456

    chris456 Regular Member

    Joined:
    May 17, 2010
    Messages:
    281
    Likes Received:
    567
    I knew that I ve'seen that somewhere , so I have found it , look here :http://www.regular-expressions.info/examples.html

    hope it will help...

    IP Addresses


    Matching an IP address is another good example of a trade-off between regex complexity and exactness. \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b will match any IP address just fine, but will also match 999.999.999.999 as if it were a valid IP address. Whether this is a problem depends on the files or data you intend to apply the regex to. To restrict all 4 numbers in the IP address to 0..255, you can use this complex beast: \b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b [​IMG] (everything on a single line). The long regex stores each of the 4 numbers of the IP address into a capturing group. You can use these groups to further process the IP number.
    If you don't need access to the individual numbers, you can shorten the regex with a quantifier to: \b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b [​IMG]. Similarly, you can shorten the quick regex to \b(?:\d{1,3}\.){3}\d{1,3}\b [​IMG]
     
    Last edited: Feb 25, 2011
  3. Crazy

    Crazy Power Member

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    Thanks chris.

    I was able to apply some of this to work on 204.15.20.0 - 204.15.23.255
    With: \b204\.15\.(2[0-3]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

    However, I'm having a hard time with this range... 69.63.176.0 - 69.63.191.255
    How would you restrict that 3rd octet? Since it starts/stops @ 6 and 1 rather than the usual 0-9 range.
     
  4. fastlinks

    fastlinks Power Member

    Joined:
    Feb 4, 2015
    Messages:
    616
    Likes Received:
    76