Definition

A regular expression (regex) is a formal notation describing a set of strings (a regular language) — used to specify token patterns for the lexer.

Key Points — Operations

Example

📌 CSS Frequency: Moderate-high — often a "write a regex for..." numeric-type question (e.g., regex for a valid email, identifier, or binary string divisible by 3).

Model Answer (short)

"A regular expression is built from union, concatenation, and Kleene closure over an alphabet, and it precisely specifies token patterns for a lexer. For example, the identifier pattern letter(letter|digit)* matches any string starting with a letter followed by letters or digits — exactly what a compiler needs to recognize variable names."