openskills.info
Course Preview

Regular Expressions

Regular expressions are patterns that describe text, so a program can search, extract, validate, or replace matching strings in a single step. They appear in editors, command-line tools, and programming languages. This topic covers the pattern grammar, how matching engines work, and where patterns fail.

itComputer fundamentals

Regular Expressions

A regular expression is a pattern that describes a set of strings. A program can use it to search text for anything that matches, to extract the matching parts, to validate that input has a required shape, or to replace matches. Every mainstream programming language ships a regex engine, and the same pattern language shows up in editors, command-line tools, and build scripts.

A regular expression is itself a string. Most characters match themselves: the pattern cat matches the text cat. A few characters, the metacharacters, carry special meaning instead. The pattern ^\d{4}-\d{2}-\d{2}$ matches strings with the shape of a YYYY-MM-DD date: a start-of-text anchor, four digits, a literal hyphen, two digits, another hyphen, two digits, and an end-of-text anchor. The phrase "regular expression" is usually shortened to regex or regexp; the terms are interchangeable.

This topic builds the pattern grammar from those pieces, then explains what happens inside the engine, because the engine explains the traps.

A pattern is a description, not a literal

Each character in a pattern is either a literal or a metacharacter. A literal matches itself. A metacharacter describes structure: a position, a set of characters, repetition, or a choice. The common metacharacters are:

. * + ? { } [ ] ( ) | ^ $ \ 

The backslash does double duty. It escapes a metacharacter so the pattern matches the literal character: \. matches a literal period. It also introduces escape sequences with their own meanings, such as \d for a digit. An escaped metacharacter and a plain letter after a backslash mean different things in different dialects, which is why the same pattern sometimes behaves differently across languages.

Character classes

Continue the course

This section is part of the paid course.

See pricing to subscribe, or log in if you already have access.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources