Reputation: 4367
I'm totally new at the Regex world and here's what I'm trying to accomplish:
[2 Chars] + [Any Amount of Digits] + [/] + [4 Digits]
For Instance:
AB001/2013
XY999537/2014
OB22/2010
Basically all I have is:
preg_match('/\b[A-Z]{2}\b/', $var);
This ensures me that I'll have only 2 characters at the beginning, but I can't seem to figure out how to make the Regex understand that now I want to add another pattern from the 3rd character of the string and forward.
What I've tried:
preg_match('/\b[A-Z]{2}\b[0-9]/', $var);
preg_match('/\b[A-Z]{2}\b\d/', $var);
preg_match('/(\b[A-Z]{2}\b)([0-9])/', $var);
And I don't understand what's wrong.
Upvotes: 0
Views: 49
Reputation: 68810
This regex should fit your needs :
preg_match('/\b[A-Z]{2}\d+\/\d{4}\b/', $var);
/*
\b # word boundary
[A-Z]{2} # 2 uppercase letters
\d+ # 1+ digits (\d = [0-9])
\/ # a slash (escaped)
\d{4} # 4 digits
\b # word boundary
*/
Upvotes: 3