I’m trying to search a string for all valid UK registration plates. I found the following regular expression which matches both pre/post 2001 UK number plates:
^([A-Z]{3}\s?(\d{3}|\d{2}|d{1})\s?[A-Z])|([A-Z]\s?(\d{3}|\d{2}|\d{1})\s?[A-Z]{3})|(([A-HK-PRSVWY][A-HJ-PR-Y])\s?([0][2-9]|[1-9][0-9])\s?[A-HJ-PR-Z]{3})$
How would I go about using that with preg_match_all to return all valid number plates found in a string?
For example:
This is some random text NV07 ABC This is A0123 ABC some more random text AB08ABC
Should return:
-
NV07 ABC
-
AB08ABC
Replace the
^and$(start and end of string) anchors with\b(start/end of word) anchors.