Pakistan Special
Pakistan Car Number Plate Regex
Vehicle registration plates in Pakistan usually start with two or three letters that identify the series, followed by up to four digits, and some plates add a two-digit registration year between them. Common written forms include LEA-1234, ABC 123 and LEB-07-4567. This pattern accepts two or three capital letters, an optional dash or space, an optional two-digit year with its own separator, and one to four digits. Formats vary by province and registration year, so this covers common shapes only. Use it to tidy parking or fleet records, and expect to extend it for older or special plates.
Pattern (JavaScript)
/^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$/Starts at the start of the line/string, then an uppercase letter, between 2 and 3 times, then one of the characters - , optionally (zero or one time), then (exactly 2 digits, then one of the characters - ), optionally (zero or one time), then a digit (0-9), between 1 and 4 times, then the end of the line/string.
Limit: Formats vary by province and registration year; this covers common shapes only.
Examples
Matches
- ✓ LEA-1234
- ✓ ABC 123
- ✓ LEB-07-4567
Does not match
- ✗ 1234-LEA
- ✗ L-1234
- ✗ LEAD-1234
Try it
0 matches (JavaScript engine)
LEA-1234
ABC 123
LEB-07-4567
1234-LEA
L-1234
LEAD-1234Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$/g;
const text = "LEA-1234";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$')
text = 'LEA-1234'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$/';
$text = 'LEA-1234';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^[A-Z]{2,3}[- ]?(?:\\d{2}[- ])?\\d{1,4}$");
String text = "LEA-1234";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$`)
text := "LEA-1234"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$");
var text = "LEA-1234";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$").unwrap();
let text = "LEA-1234";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^[A-Z]{2,3}[- ]?(?:\d{2}[- ])?\d{1,4}$/
text = 'LEA-1234'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why does it not accept lowercase letters?
- Plates are printed in capitals, so the pattern keeps the class uppercase. Convert input to uppercase first, or add the i flag if you prefer.
- Does this cover every province's format?
- No. Formats vary by province and registration year; this covers common shapes only. Check sample plates from your region and extend the pattern where needed.
- Can it read plates from photos?
- No. A regex only checks text. Use an OCR tool to read the image, then use this pattern to clean up and check the recognised text.