Help with a regexp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shujaa
Forum Newbie
Posts: 13
Joined: Tue Jan 27, 2004 12:14 pm

Help with a regexp

Post by Shujaa »

Hi again, need a quick helper with the syntax for regular expressions. Basically I need to match the first 2 letters of a submitted postcode with a list of postcodes that I know are in a certain area (London), to determine that the user is living in London. The list itself is quite long but is sequential, ie:

E1-E18 are all in, as are:
WC1-WC2
EC1-EC4
N1-N22
NW1-NW11
SE1-SE28
SW1-SW20
W1-W14

I just need to build a regexp that can match any of those ranges of values, but I'm a complete newbie at regexps, and can't even figure out how to specify a logical "OR" clause for the regexp to match with... would appreciate any help.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

OR is specified as | character, ie /(something|something_else)/ reads as something or something_else. It's true for both the PCRE and POSIX regexps.
Post Reply