Skip to main content

Regular Expression

In Turkish
Düzenli ifade
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/regular-expression

In short

A regular expression, or regex, is a pattern written in a compact syntax that describes text to search for, validate, extract or replace within strings.

What is a regular expression?

A regular expression is a small pattern language for describing text. The pattern \d{3}-\d{4} means "three digits, a hyphen, then four digits", and a regex engine can use it to check whether a string matches, find every match in a document, pull out parts of each match or replace them. Almost every programming language, text editor and command-line tool such as grep and sed supports regular expressions.

Patterns are built from a few pieces. Literal characters match themselves, character classes like [a-z] or \d match one character from a set, quantifiers like *, +, ? and {2,5} say how many times something repeats, and the anchors ^ and $ pin a match to the start or end of the text. Parentheses create groups that can be captured and reused, and flags change behavior, such as i for case-insensitive matching or g for finding all matches in JavaScript.

A regex is like a search filter with wildcards: instead of looking for one exact word, you describe the shape of what you want. Common uses include validating input such as postal codes, parsing log lines, finding and renaming things across a codebase and cleaning up data. Regexes are also easy to get wrong and hard to read, so it's best to keep them short, comment them and test them against both matching and non-matching examples.

Regular expressions are often confused with the glob patterns used for file names. In a glob, *.txt means "any file ending in .txt", while in a regex * means "repeat the previous item", so the equivalent regex is ^.*\.txt$. Regexes are also a poor tool for parsing nested formats like HTML or JSON, which need a real parser. Patterns with nested repetition can take exponential time on certain inputs, a denial-of-service risk known as ReDoS.

Key takeaways

  • A regex is a pattern that describes the shape of text to match.
  • Character classes, quantifiers, anchors and groups are its main building blocks.
  • It is used for searching, validating, extracting and replacing text.
  • Glob patterns for file names look similar but follow different rules.
  • Complex regexes are hard to read and can be slow, so keep them small and tested.

Example

Extracting and replacing with regex in JavaScriptjavascript
const log = "2026-09-30 ERROR [auth] Login failed for user=ada";

// Capture the date, the level and the user name
const pattern = /^(\d{4}-\d{2}-\d{2}) (\w+) .*user=(\w+)$/;
const match = log.match(pattern);

if (match) {
  const [, date, level, user] = match;
  console.log(date, level, user); // 2026-09-30 ERROR ada
}

// Replace every digit with #
console.log("Call 555-0142".replace(/\d/g, "#")); // Call ###-####

Readers ask

What does regex stand for?

Regex is short for regular expression, a term from formal language theory in the 1950s. The spelling regexp is also common, for example in JavaScript's RegExp object.

Are regular expressions the same in every language?

The basics are shared, but details differ between flavors such as POSIX, PCRE, JavaScript, Python and .NET. Features like lookbehind, named groups and Unicode classes vary, so test a pattern in the language where it will actually run.

Should I validate email addresses with a regex?

A simple regex can catch obvious typos, but a fully correct email pattern is extremely complex. The reliable check is to send a confirmation message to the address.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings