regular expression
A pattern language for matching text, where characters such as ., *, ^ and $ have special meanings.
In more detail
A dot matches any single character, a star repeats the item before it, ^ anchors to the start of a line and $ to the end, and square brackets match one character from a set. Tools such as grep, sed and awk use them, as do most programming languages, with small differences in syntax. Escape a special character with a backslash when you mean it literally.
Examples
grep -F '4.50' prices.txtgrep '4\.50' prices.txt[[ $line =~ ^[0-9]+$ ]]The token resolver uses ^\{([^}]+)\}$ to recognise an alias value and capture the token path inside the braces.Structured logs avoid regular-expression parsing of log messages.git log --grep '^feat'git config --get-regexp '^alias'grep -Eq "^(feat|fix): .+"A native Node.js router can match request paths with a pattern such as /^\/users\/(\d+)$/ and pull out the ID.Pulling an amount out of prose logs needs a regular expression that silently breaks when the wording changes.PromQL regex matcher: http_requests_total{route=~"/api/.*"}import re
re.findall(r"\d+", "3 cats, 12 dogs") # ["3", "12"]Regular expressions are the right tool for free-text logs such as sshd lines; for JSON, walk the parsed structure instead.PostgreSQL: WHERE name ~* 'cable' (~* ignores case). SQLite has a REGEXP operator but no built-in implementation.WHERE name ~* 'cable'In this course: pytest.raises takes a match argument that is a regular expression searched for in the error message, so a test can check that the right error was raised for the right reason. For example, match="no rate for" passes if that text appears anywhere in the error message.with pytest.raises(KeyError, match="MOON"):Related terms
- grep — The command that prints the lines of its input that match a pattern.
- extended regular expression — The two regular expression dialects of Unix tools: basic (BRE), used by grep and sed by default, and extended (ERE), selected with -E.
- character class — A regular expression or glob part in square brackets that matches any one character from a set, such as [abc] or [a-z].
- glob pattern — A pattern that matches names using * for any run of characters, a question mark for one character and [abc] for one of a set.
- Gitleaks — An open-source secret scanner for Git repositories and files, configured with TOML rules that combine regular expressions, keywords and entropy.
- token alias — A token whose value is a reference to another token, written in curly braces such as {semantic.action.bg}.
- structured logging — Writing each log entry as named fields, such as status, duration and request identifier, instead of a free-text sentence.
- commit limiting — git log options that keep only the commits you ask about, by count, date, author or words in the message.
- matcher (middleware) — The config.matcher option exported from middleware.ts that lists which paths the middleware runs on.
- routing — Choosing which piece of code handles a request, based on its method and path, such as GET /users/42.
- path parameter — A value embedded in the path of a URL, such as 42 in /users/42, which a router extracts by matching a pattern.
- label matcher — A condition on a label inside a PromQL selector: = for an exact value, != to exclude, =~ and !~ for regular expressions.
- string method — A method that belongs to strings, such as upper, lower, count, find, replace, split, strip, startswith or join.
- find() — A string method that returns the index where a substring first appears, or -1 if it does not appear.
- parsing — Breaking a raw log line into named fields, such as time, user and source address, that rules and searches can use.
- Python — A popular general-purpose programming language known for readable code and a large standard library.
- LIKE — An operator that matches text against a pattern, where % stands for any run of characters and _ for exactly one.
- ILIKE — An operator, available only in PostgreSQL, that works like LIKE but ignores upper and lower case.
- PostgreSQL — A widely used open source relational database server with strict typing, rich data types and extensions.
- pytest.raises — A pytest helper, used in a with block, that makes a test pass only if the code inside raises the named exception.
- exception — An error object a program raises to stop normal flow and report that something went wrong.
Taught in
- Reasoning Techniques — AI Engineering: LLM Apps, RAG & Agents
- Structured Output — AI Engineering: LLM Apps, RAG & Agents
- Guardrails, Privacy And Governance — AI Engineering: LLM Apps, RAG & Agents
- Finding Lines: grep And Regular Expressions — Bash Scripting & Command Line Automation
- Reshaping Text: cut, sort, uniq, tr, sed, awk — Bash Scripting & Command Line Automation
- Trimming, Replacing And Changing Case — Bash Scripting & Command Line Automation
- Style That Prevents Bugs — Bash Scripting & Command Line Automation
- POSIX sh Versus Bash — Bash Scripting & Command Line Automation
- Filters, Parameters And A Workflow From A Push — Certified Argo Project Associate (CAPA) Exam Prep
- Final Mock, Review And A Trap Sprint — Certified Argo Project Associate (CAPA) Exam Prep
- AWS Organizations, Account Hierarchies & Azure Management Groups — Cloud Security & DevSecOps Engineering
- Pre-Commit Secret Scanning with Gitleaks & Entropy — Cloud Security & DevSecOps Engineering
- Static Application Security Testing with Semgrep — Cloud Security & DevSecOps Engineering
- Software Composition Analysis with Trivy — Cloud Security & DevSecOps Engineering
- Supply Chain Security: SBOMs & Cosign Signing — Cloud Security & DevSecOps Engineering
- Securing the Kubernetes Control Plane & Node Components — Cloud Security & DevSecOps Engineering
- CIA Triad, Non-Repudiation & Parkerian Hexad — Cybersecurity Fundamentals, GRC & Cryptography
- Threat Actors, Motivations & Cyber Kill Chain — Cybersecurity Fundamentals, GRC & Cryptography
- Defense-in-Depth & Security Control Categories — Cybersecurity Fundamentals, GRC & Cryptography
- Asset Lifecycle Management & Media Sanitization — Cybersecurity Fundamentals, GRC & Cryptography
- Data Loss Prevention & Egress Monitoring — Cybersecurity Fundamentals, GRC & Cryptography
- Design Tokens: W3C Specs, Global, Semantic & Component Tokens — Design Systems & Component Engineering
- Codebase And Dependencies — DevOps & Site Reliability Engineering
- Disposability, Dev Prod Parity And Logs — DevOps & Site Reliability Engineering
- Structured Logging & Correlation IDs: Context Stitching — Production Full-Stack Engineering
- Installing Git, And Telling It Who You Are — Advanced Git Internals & Distributed Workflows
- Conventional Commits — Advanced Git Internals & Distributed Workflows
- Route Handlers: RESTful Endpoints with NextRequest — Next.js 15 & Modern App Router Architecture
- Edge Middleware: Auth Verification & Route Matchers — Next.js 15 & Modern App Router Architecture
- Routing & Middleware: Path Parsing & Async Context — Node.js Internals & Backend Services
- Observability Versus Monitoring — Full-Stack Observability: Metrics, Tracing & Logging
- Structured Logging And Why Text Fails — Full-Stack Observability: Metrics, Tracing & Logging
- PromQL Basics And Selectors — Full-Stack Observability: Metrics, Tracing & Logging
- Forty Seconds At Two: Push, Pull And Service Discovery — Prometheus Certified Associate (PCA) Exam Prep
- A Week Without A Scrape: Configuration And Relabelling — Prometheus Certified Associate (PCA) Exam Prep
- Fundamentals Sprint: Nine Calls On The Server — Prometheus Certified Associate (PCA) Exam Prep
- The Server That Would Not Die: Selecting Data — Prometheus Certified Associate (PCA) Exam Prep
- PromQL Sprint: Ten Queries At Minute Twenty Two — Prometheus Certified Associate (PCA) Exam Prep
- One Week, Three Objectives: Final Review — Prometheus Certified Associate (PCA) Exam Prep
- A Standard Library Tour — Hands-on Python: Complete Video Course & Book
- SIEM Architecture: Ingestion Pipelines & Indexing — Security Operations & Threat Hunting (SOC)
- Event Correlation Rules, Thresholds & Anomaly Pipelines — Security Operations & Threat Hunting (SOC)
- Log Parsing, Schema Normalization (OCSF/ECS) & Extraction — Security Operations & Threat Hunting (SOC)
- YARA Rule Authoring & File Signature Matching — Security Operations & Threat Hunting (SOC)
- Adversary Tactics, Techniques & Procedures (TTP) Mapping — Security Operations & Threat Hunting (SOC)
- Indicator of Compromise Extraction & Threat Hunting Feeds — Security Operations & Threat Hunting (SOC)
- Incident Triage, Severity Scoping & Communication — Security Operations & Threat Hunting (SOC)
- Post-Incident Review & Root Cause Analysis — Security Operations & Threat Hunting (SOC)
- Malware Triage: Hashes, Strings & Sandboxing — Security Operations & Threat Hunting (SOC)
- Filtering With The WHERE Clause — PostgreSQL, Indexing & Relational Data Modeling
- Making Failures Explain Themselves — Automated Testing, TDD & Quality Engineering
- The Cleanup That Emptied The Wrong Directory: Shell Scripts Under Exam Conditions — CompTIA Linux+ (XK0-006) Exam Prep
- The Assistant Was Confident: Reviewing AI-Generated Code, Prompts And Data — CompTIA Linux+ (XK0-006) Exam Prep
- Deploying Files: file, copy, lineinfile And blockinfile — RHCE in Ansible (EX294): Automate Red Hat Systems
- Handlers And Failure: notify, block, rescue And always — RHCE in Ansible (EX294): Automate Red Hat Systems
- SELinux: Labels, Ports And Booleans That Persist — RHCE in Ansible (EX294): Automate Red Hat Systems
References
- POSIX Regular Expressions
- GNU grep manual: Regular Expressions
- Python documentation: re
- regex(7) manual page (man7.org)
- MDN: regular expressions
- MDN glossary: Regular expression
- Prometheus: querying basics
- Regular expression HOWTO
- PostgreSQL: POSIX regular expressions
Certification courses
- AWS AIP-C01 course and practice exam: AI engineering with LLM apps, RAG and agents
- CAPA course and practice exam: Certified Argo Project Associate
- PCA course and practice exam: Prometheus Certified Associate
- CompTIA Linux+ course and practice exam: XK0-006
- RHCE course and practice exam: Red Hat Certified Engineer in Ansible (EX294)