शब्दकोश · प्रोग्रामिंग

Regex (Regular Expression)

A regular expression is a compact pattern language for matching, searching and replacing text, used for validation, parsing and log filtering.

अपडेट: अक्टूबर 6, 2026

A regex (regular expression) is a sequence of characters that defines a search pattern. You use it to find, validate, extract or replace text, for example to check that a string looks like an email address or to pull status codes out of a log file.

Why it matters

Regex turns many lines of string-handling code into one pattern and is built into most languages, editors and command-line tools such as grep. Syntax details vary slightly between engines, so a pattern should be tested in the engine you will actually use.

Example

Pattern:  ^(\d{3}) (GET|POST) (\S+)$
Text:     404 GET /missing-page
Groups:   1 = 404, 2 = GET, 3 = /missing-page

\d{3} matches exactly three digits, (GET|POST) matches either word, \S+ matches non-space characters, and ^ and $ anchor the start and end of the line.

Common mistakes

  • Forgetting to escape special characters such as ., which matches any character, not a literal dot.
  • Writing nested quantifiers like (a+)+ that cause catastrophic backtracking and freeze the program on certain input.
  • Using regex to fully validate emails or parse HTML, where a dedicated parser or library is safer.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.