Regex Builder
A regex that matches your description, with a line-by-line explanation and 3 worked examples.
More from Engineering
What you get
Get a regex that matches your description, with a line-by-line explanation and 3 worked examples, all for £1.00.
Who it's for
- Web developers working with form validation
- Data analysts cleaning datasets
- Software engineers parsing log files
Use cases
- Extracting specific data from a large dataset
- Validating user input on a web form
- Parsing log files to identify trends
- Cleaning up messy data for analysis
- Creating custom filters for data processing
FAQ
what format is the regex in
The regex is in PCRE, POSIX, or JS flavour, depending on the most suitable format for your needs. You'll also get a token-by-token explanation and 3 worked examples.
how many examples do i get
You'll get 3 worked examples, showing how the regex matches different inputs, with capture groups labelled for clarity.
what if my description is ambiguous
If your description is ambiguous, we'll flag it and choose the most useful interpretation, ensuring you get a regex that meets your needs.
can i get multiple regexes
No, you'll get one regex that best matches your description, along with explanations and examples, all for £1.00.
Sample output
**UK Postcode Regex (PCRE):** `/^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$/i`
**Token-by-Token Explanation:**
1. `^` - Start of the string.
2. `[A-Z]{1,2}` - Matches the first part of the postcode (one or two letters, e.g., "SW" or "M").
3. `\d` - Matches the first digit of the postcode.
4. `[A-Z\d]?` - Optionally matches a letter or digit (for postcodes like "M1 1AE" or "SW1A 1AA").
5. ` ?` - Optionally matches a space character.
6. `\d` - Matches the next digit of the postcode.
7. `[A-Z]{2}` - Matches the final two letters of the postcode.
8. `
Regex Builder | Harnests
- End of the string.
9. `i` - Flag for case-insensitive matching.
**Worked Examples:**
1. Input: "SW1A 1AA" → Match: "SW1A 1AA"
2. Input: "M1 1AE" → Match: "M1 1AE"
3. Input: "sw1a1aa" → Match: "sw1a1aa"
Note: The case-insensitive flag (`i`) allows the regex to match postcodes regardless of the case used in the input string.Last updated: 2026-06-28