Regex Explainer

Regex for a semantic version

Escaped dots, and what happens when you forget to escape them.

/^\d+\.\d+\.\d+$/

Match a whole string consisting of one or more of a digit, then ".", then one or more of a digit, then ".", then one or more of a digit.

What to check

  • Note

    Anchors match string ends, not line ends

    Without the m flag, ^ and $ match only the very start and end of the input — not the start and end of each line. On multi-line input this is often not what was intended.

    Fix: Add the m flag if the pattern should apply per line.

Step by step

  1. ^

    Anchor to the start of the input.

  2. \d+

    Match one or more of a digit.

  3. .

    Match ".".

  4. \d+

    Match one or more of a digit.

  5. .

    Match ".".

  6. \d+

    Match one or more of a digit.

  7. $

    Anchor to the end of the input.

Details

Capture groups
None
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