Regex Explainer

Greedy vs lazy quantifiers

The same pattern with and without the lazy modifier, and what each one actually consumes.

/<(.+?)>/

Match "<", then (one or more of any character, as few times as possible), then ">".

What to check

  • Probably a bug

    Unanchored — matches anywhere in the input

    Without ^ and $ the pattern succeeds if it matches ANY substring. A validator meant to check a whole value will therefore accept anything that merely contains a valid value: an email pattern without anchors accepts "nonsense a@b.co nonsense".

    Fix: Wrap the pattern in ^ and $ if it is validating a whole string. Leave it unanchored only if you are genuinely searching within text.

  • Probably a bug

    Unescaped dot matches any character

    A dot among literal characters matches ANY character, not a period. So a pattern written for "1.2" also matches "1x2", and one written for "example.com" matches "exampleXcom".

    Fix: Escape intended periods as \. — or use a character class [.].

Step by step

  1. <

    Match "<".

  2. (.+?)

    Match (one or more of any character, as few times as possible).

  3. >

    Match ">".

Details

Capture groups
1
Flags
None set

Check your own pattern

Paste one on the home page, or call the API or MCP server. This page is also available as markdown.

Related examples