Learn to build software with AI. Free. →Agents, skills, MCP, local models, and the fundamentals. 87 courses, 17 books, 222 tools.
Sponsors Creem+ Become a sponsor
Sponsored CreemSell Software Globally - with zero headaches+Become a sponsorGet your product in front of developers.
← All posts

Blog post

How to use JavaScript Regular Expressions

In this post

Introduction to Regular ExpressionsHard but usefulHow does a Regular Expression look likeHow does it work?AnchoringMatch items in rangesMatching a range item multiple timesNegating a patternMeta charactersRegular expressions choicesQuantifiers+*${n}${n,m}Optional itemsGroupsCapturing GroupsOptional groupsReference matched groupsNamed Capturing GroupsUsing match() and exec()Noncapturing GroupsFlagsInspecting a regexEscapingString boundariesReplacing using Regular ExpressionsGreedinessLookaheads: match a string depending on what follows itLookbehinds: match a string depending on what precedes itRegular Expressions and UnicodeUnicode property escapesExamplesExtract a number from a stringMatch an email addressCapture text between double quotesGet the content inside an HTML tag
Home / JavaScript

How to use JavaScript Regular Expressions

By Flavio Copes

Apr 30, 2018updated Jul 18, 2026

Learn how to use JavaScript regular expressions to search, validate, extract, and replace text, with practical examples of patterns, groups, and flags.

~~~
  • Introduction to Regular Expressions
  • Hard but useful
  • How does a Regular Expression look like
  • How does it work?
  • Anchoring
  • Match items in ranges
  • Matching a range item multiple times
  • Negating a pattern
  • Meta characters
  • Regular expressions choices
  • Quantifiers
    • +
    • *
    • {n}
    • {n,m}
  • Optional items
  • Groups
  • Capturing Groups
    • Optional groups
    • Reference matched groups
    • Named Capturing Groups
  • Using match() and exec()
  • Noncapturing Groups
  • Flags
  • Inspecting a regex
  • Escaping
  • String boundaries
  • Replacing using Regular Expressions
  • Greediness
  • Lookaheads: match a string depending on what follows it
  • Lookbehinds: match a string depending on what precedes it
  • Regular Expressions and Unicode