|
Home > Archive > MySQL Server Forum > June 2005 > Regex
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Jon Cooper 2005-06-24, 11:23 am |
| 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,lette
r,number,number,spac
e,number,letter,lett
er) 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!!
Jon
| |
| Bill Karwin 2005-06-24, 8:23 pm |
| Jon Cooper wrote:
> 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...
Try this:
postcode REGEXP '^([A-Z]{2}[0-9]{1,2}|[A-Z][0-9]{2}) [0-9]{3}$'
Regards,
Bill K.
|
|
|
|
|