TL;DR

Three steps: anchor the position (^ $), match the content (\d \w, classes), then control quantity (+ * {n,m}).

Basics

SyntaxMeaning
.Any character (usually not newline)
\d / \w / \sDigit / word char / whitespace
[abc] / [^abc]Class / negated class
^ / $Start / end of line
* / + / ?0+ / 1+ / 0 or 1
{n,m}n to m times
(...) / (?:...)Capturing / non-capturing group
`ab`Alternation
\bWord boundary

Common Patterns

TargetPattern
Email (simplified)[\w.+-]+@[\w-]+\.[\w.-]+
URL (simplified)https?://[^\s]+
Date yyyy-mm-dd\d{4}-\d{2}-\d{2}
IPv4(\d{1,3}\.){3}\d{1,3}

Notes

Sources

最后更新:2026-08-02