SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex matching numerical ranges

    Hi, I'm trying to write an RE to match a postcode range, an example of what i need to match is a postcode begining with HE then the next digits between 7 and 13, i.e. from HE7 to HE13.

    The only way I know how to write this is:

    ^HE(7|8|9|10|11|12|13)

    Is there a more efficient way? That example doesnt look much bother but I have some others like AL231 to AL892, which, with my way would be:

    ^AL(231|232|233|234 .... 889|890|891|892)

    (dots represent all numbers between 234 and 889)

    I couldn't find anything in my books or by searching. My first instinct was to try

    ^HE[7-13]

    which isn't allowed.

    I hope I have explained my problem well enough. Thank you.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not much of an improvement, but:
    ^HE([7-9]|1[0-3])
    ^AL(23[1-4]|2[4-9][0-9]|[3-7][0-9]{2}|8[0-7][0-9]|889|89[0-2])


    I think it would be more efficient to use ^HE[0-9]{1,2} and ^AL[0-9]{3} and verify the ranges later, if at all possible.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you, i think that is as efficient notation i can hope for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •