Thread: Number range

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2008
    Posts
    17
    Rep Power
    0

    Question Number range


    hi

    I have strings in a pattern like this:
    Code:
    /sites/pages/1999/index.html
    /sites/pages/2000/index.html
    /sites/pages/2001/index.html
    /sites/pages/2002/index.html
    /sites/pages/2003/index.html
    and so on...

    see the pattern ?
    the range is from 1999 to 2014

    I need my regExp to capture every string in which the number is lower than "2014":
    Code:
    /sites/pages/2014/index.html
    so I need something like this:
    Code:
    /sites/pages/[1999-2013]/index.html
    help please ?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    regexes are string tools. They can process (simple) strings. They're not for math or date calculations or whatever.

    Use a regex to grab the number. And then check the actual value with your application:

    PHP Code:
    $number >= 1999 && $number <= 2014 
    Yes, theoretically, it is possible to compare numbers by checking the digits. But don't go down that road, it will make you the most hated person amongst everybody who has to read your code.

    Comments on this post

    • Laurent_R agrees : Yes, I agree, this is not really a job for regex.
    Last edited by Jacques1; September 11th, 2013 at 06:28 AM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2008
    Posts
    17
    Rep Power
    0
    Originally Posted by Jacques1
    Use a regex to grab the number. And then check the actual value with your application:

    PHP Code:
    $number >= 1999 && $number <= 2014 
    I can't use that.
    this something that is suppose to be in .htaccess
    Last edited by Kravvitz; September 11th, 2013 at 03:59 PM. Reason: must we quote the whole post? :p
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    What exactly are you trying to do? Using hard-coded dates in a htaccess sounds pretty weird to me.

    Anyway, I guess you don't care and simply want to get it done:

    Code:
    (?:1999|20(?:0[0-9]|1[0-4]))
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2008
    Posts
    17
    Rep Power
    0
    Originally Posted by Jacques1
    What exactly are you trying to do? Using hard-coded dates in a htaccess sounds pretty weird to me.

    Anyway, I guess you don't care and simply want to get it done:

    Code:
    (?:1999|20(?:0[0-9]|1[0-4]))
    thanks

IMN logo majestic logo threadwatch logo seochat tools logo