Regex

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Cooper

    #1

    Regex

    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,n umber,space,num ber,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

    #2
    Re: Regex

    Jon Cooper wrote:[color=blue]
    > 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...[/color]

    Try this:

    postcode REGEXP '^([A-Z]{2}[0-9]{1,2}|[A-Z][0-9]{2}) [0-9]{3}$'

    Regards,
    Bill K.

    Comment

    Working...