Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
hi folks -

I know very little about regex so this is bound to be simple...

I need to scan thru a db and check postcodes are in the format AB1 123, AB10
123 or A12 123.

Now I know I need to use regex but am struggling with the syntax...

I thought postcode REGEXP '([a-z][a-z][0-9][0-9] [0-9][a-z][a-z])' might do
it for the second
pattern(letter,letter,number,number,space,number,letter,letter) but all this
seems to do is ignore the sequence and just says 'does this include numbers
and letters and spaces?' Yep? ok then its a pass even when the pattern is
not what I want.

help please!!


Re: Regex

Jon Cooper wrote:
Quoted text here. Click to load it

Try this:

postcode REGEXP '^([A-Z][0-9]|[A-Z][0-9]) [0-9]$'

Bill K.

Site Timeline