SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Regex matching numerical ranges
-
Dec 14, 2006, 04:12 #1
- 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.
-
Dec 14, 2006, 05:46 #2
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- 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
-
Dec 14, 2006, 09:01 #3
- 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