Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REGEXP - Checking Postcode

Status
Not open for further replies.

MSRez

Programmer
Dec 22, 2004
57
0
0
EU
I'm not really familar with using regexp with MySQL so hopefully this shouldn't be too difficult for anyone in the know.

I'd like to match the start of postcodes to certain letters e.g. the postcode beginning with S should match postcodes beginning with S followed by a number, followed by any series of characters. For instance, S14 3WA would be matched whereas SW4 9LA should not match.

So far, the regex I have is just REGEXP '^[S0-9.]' but obviously it doesn't work.

Thanks in advance for your help.
 
try ^S[0-9]. but that would match anything that starts with S followed by at least one number ...
 
Thanks, that works a treat! I adjusted it to support multiple starting letters - '^(S|E|NW)[0-9].'

I would like a second query that does in effect the opposite of this. How do I form an exclusion query based on the same criteria? So anything that doesn't contain those starting letters.
 
Much more simple than I thought - simply use NOT REGEXP.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top