Skip to content

Guide · Open source

How to use learn-regex: a beginner's regex tutorial

Updated · written with AI from the project's own documentation and checked against our catalogue data

learn-regex is a written tutorial, published as a GitHub README, that explains regular expressions (regex) from the ground up. It is aimed at beginners, developers who use search-and-replace or form validation, and students meeting text processing for the first time. By the end of the guide you will know what the main regex symbols mean and how to check each example in a browser tester.

learn-regexziishaned/learn-regex · ★ 46.1k · MIT

Quick start

  1. 1Open the README. Go to the learn-regex repository on GitHub and open README.md, the English version.
  2. 2Read the basics. Start with Basic Matchers and Meta Characters to learn literal text, the full stop and character sets.
  3. 3Run each example. Click the Test the regular expression link under an example to open it on regex101.com.
  4. 4Edit the pattern. Change one symbol in the pattern on regex101.com and watch which matches change.
  5. 5Work through repetition and groups. Read the sections on repetitions, braces, capturing groups and alternation.
  6. 6Finish with lookarounds and flags. Read the lookaround and flag sections, then test them the same way.

What you need before you start

learn-regex does not need to be installed. You read it online in the README on GitHub, and the source lists no prerequisites. The project is licensed under MIT and is also offered as a PDF through a linked page on gum.co.

  • Install method: read online, no software setup listed
  • Prerequisites: none listed in the source
  • Optional: a browser tab open to regex101.com so you can test examples

What a regular expression is

A regular expression is a pattern that is matched against a subject string from left to right. Regex is used to replace text, validate forms, and extract a substring based on a pattern match. The tutorial uses a username rule as its first example: letters, numbers, underscores and hyphens, with a limit on length. That pattern accepts john_doe and john12_as, and rejects Jo because it contains an uppercase letter and is too short.

Learn basic matchers and character sets

A plain pattern such as the matches the same letters in the same order, and regex is case-sensitive by default, so The does not match the. Square brackets define a character set: [Tt]he matches The or the. A hyphen inside brackets specifies a range, and a period inside brackets is a literal period. A caret right after the opening bracket negates the set, so [^c]ar matches par and gar but not car.

[Tt]he

Understand repetition and the meta characters

The symbols * (zero or more), + (one or more) and ? (optional) control how many times the preceding item can occur. Braces {n,m} set a minimum and maximum count. The README also covers the full stop (any single character except a line break), alternation with a pipe, escaping reserved characters with a backslash, and anchors ^ and $ for the start and end of the input.

  • * matches 0 or more repetitions
  • + matches 1 or more repetitions
  • ? makes the preceding symbol optional
  • {n,m} matches at least n and at most m repetitions
  • ^ matches the beginning of the input and $ matches the end
\s*cat\s*

Use lookarounds, flags and greedy vs lazy matching

The later sections cover positive and negative lookahead and lookbehind, the flags for case-insensitive, global and multiline search, and the difference between greedy and lazy matching. Each section links to a regex101.com example you can run. Note that the README covers general concepts, so check your own language's documentation for exact syntax details.

  • Positive and negative lookahead
  • Positive and negative lookbehind
  • Case-insensitive, global and multiline flags
  • Greedy vs lazy matching

What people use it for

  • Designing a username rule that allows letters, numbers, underscores and hyphens within a length limit
  • Checking that a form field matches an expected pattern before submission
  • Finding every word or number in a text with a shorthand or character-set pattern
  • Replacing text in a document with a pattern instead of an exact string

Frequently asked questions

Is learn-regex free?

The repository is licensed under MIT, and the README is readable online at no cost. The source also links to a PDF version through a gum.co page, which is a separate offer from the same link.

Do I need to install anything to use learn-regex?

No. The source lists the install method as read-online with no prerequisites and no install commands. You only need a web browser to read it and to open the regex101.com examples.

Does learn-regex teach one specific regex language?

No. The README covers general regex concepts rather than language-specific syntax. If you need the exact rules for one language such as JavaScript or Python, check that language's own documentation after reading.

Are there exercises in learn-regex?

The material is a written tutorial with linked examples, not interactive exercises. You learn by reading each example and testing the pattern yourself on regex101.com.

How does learn-regex compare to regexone or regexr?

The source names regexone, regexr and Regex101 as comparable projects but does not compare them in detail. learn-regex is a written reading guide with linked examples, while the others are listed as alternatives you can explore to see which style suits you.

Why is my regex not matching in my code?

The source notes that regular expressions are normally case-sensitive, so The will not match the. It also says a caret after an opening bracket negates a set, so check where you placed symbols. For language-specific behaviour, consult your language's documentation.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

learn-regex suits beginners and developers who want a clear, free, written introduction to regex that they can check in a browser. It is less suitable if you need a reference for one specific regex flavor or want interactive exercises, so pick a language reference or an exercise-based tool for those needs.

Install options & downloads