Skip to main content

Dev & Computing · 正则表达式(Regex) · Updated 2026-10-25

What Is Regular Expressions?

Definition

Regex describes string patterns: ^ start, $ end, [0-9] a set, \d digit, \w word char, \s whitespace, {2,4} repetition, (?:…) non-capturing group, (?=…) lookahead. Two classic traps: greedy .* eats as much as possible (<.*> swallows the whole tag line) — use lazy .*?; and catastrophic backtracking ((a+)+b) grows exponentially on non-matches — avoid nested quantifiers. Workhorses: phone ^1[3-9]\d{9}$ and a simplified email ^[\w.-]+@[\w.-]+\.\w{2,}$.

Formula

Phone: ^1[3-9]\d{9}$; lazy quantifier: .*?; lookahead: (?=\d{4})

Worked Example

To pull "¥129.90": /¥(\d+(?:\.\d{2})?)/ captures "129.90" in group 1, with (?:) keeping decimals out of the capture numbering.

Common Misconception

"Regex can parse HTML/JSON" — nested structures are beyond regular languages in principle; use a parser. And "it matched, so it's valid" — regex checks format only; an email that matches can still bounce. Real validation requires a confirmation mail.

Matching Calculators

Related Terms

Keep Exploring

Browse the full glossary, or head back to the homepage for 1,435 free online calculators.

Back to glossary