Toolpuffin

    Loading...

    Up and down to choose, Enter to open, Esc to close.

    Regex Examples You Can Copy: Starts With, Ends With, Dates, Postcodes and More

    Updated November 2026

    Written by the Toolpuffin team. Tools in this guide are tested in the browser.

    The fastest way to learn regex is to start from a pattern that works and change it. This guide gives copyable examples for common jobs, says what each one matches and is honest about what a regex can and cannot check.

    Try the tool: Regex Tester

    How to read the table

    Each row has a goal, a pattern and a text it matches. The patterns use ^ for the start of the text and $ for the end, so they check the whole text. Remove them to find the pattern inside longer text.

    Examples

    GoalPatternMatches
    Digits only^\d+$2026
    Starts with http or https^https?://https://example.com
    Ends with .pdf\.pdf$report.pdf
    Date in the shape YYYY-MM-DD^\d{4}-\d{2}-\d{2}$2026-11-27
    Dutch postcode^[1-9]\d{3}\s?[A-Za-z]{2}$1012 AB and 9711AA
    Hex colour^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$#0b6b5c and fff
    Spaces at the start or end^\s+|\s+$ hello (use the g flag)
    Two or more spaces in a row {2,}a b
    Text between double quotes"([^"]*)""hello" (the group holds hello)
    A simple email shape^[^\s@]+@[^\s@]+\.[^\s@]+$name@example.com

    What a regex cannot check

    • A date pattern checks the shape only. 2026-99-99 also matches, because the pattern does not know which months and days exist.
    • An email pattern checks the shape too. It cannot tell whether the address exists. The rules for real email addresses are too complex for a short pattern.
    • The postcode pattern follows the common Dutch format of four digits and two letters. It does not check whether the postcode is in use.

    Starts with and ends with

    ^ matches the start and $ matches the end. ^abc matches text that starts with abc, and abc$ matches text that ends with abc. With the multiline flag they work on every line.

    To match text that starts with one thing and ends with another, put them together, for example ^Dear.*regards$.

    Test and change a pattern

    1. Open the regex tester.
    2. Paste a pattern from the table and a few lines of text.
    3. Check the highlights, then change the pattern a little at a time.

    The tester uses the JavaScript flavour. If you use the pattern in another language, test it there as well.

    More guides