Whilst I understand the concept of finding a matching pattern using eregi I am struggling a little with the syntax - can you help?

I need to match the following:

TWO UPPER CASE A-Z
SINGLE DIGIT 0-9
MANDATORY SPACE
SINGLE DIGIT 0-9
TWO UPPER CASE A-Z

and currently have:
$pattern1="[A-Z]{2}[1-9][:space:][1-9][A-Z]{2}";

Alaso need to match:
TWO UPPER CASE A-Z
TWO DIGITS 0-9
MANDATORY SPACE
SINGLE DIGIT 0-9
TWO UPPER CASE A-Z

and currently have:
$pattern2="[A-Z]{2}[1-9]{2}[:space:][1-9][A-Z]{2}";

Many Thanks,

CAB

😕

    Eregi is crap, use the preg stuff instead.

    $pat = '/[A-Z]{2}\d \d[A-Z]{2}/';  your first pattern
    
    $pat2 = '/[A-Z]{2}\d{2} \d[A-Z]{2}/';  your 2nd pattern
    
    

    /d means any digit, a replace for [0-9]

      Sorry I'm not familiar with 'preg'.

      How do I do the check? What is the syntaz

      I currently have:

      if (eregi($pattern1,$postcode))

      Thanks for very prompt reply!

        He means use preg_match like this:

        $pat = '/[A-Z]{2}\d \d[A-Z]{2}/';   // your first pattern
        $pat2 = '/[A-Z]{2}\d{2} \d[A-Z]{2}/';  //  your 2nd pattern 
        if (preg_match($pat,$postcode) != 0 ) {
          // first pattern matched
        }
        
        if (preg_match($pat2,$postcode) != 0) {
         // second pattern matched
        }
          Write a Reply...