한국어 | English | 日本語
Senior Web Application Developer (8.8+ years)
Tech & Dev
engineering
Focusing on web frontend and backend development

Regular Expressions Explained in One Page

Regex, which often appears as an arcane language, is in fact an essential tool for developers, proving useful for a lifetime once mastered. From log analysis to data validation, we explore an efficient syntax system that solves complex text pattern matching encountered in real-world scenarios with just a single line of expression.
This article introduces the use cases and fundamental principles of Regular Expressions, a core skill for developers. It systematically organizes methods for searching complex patterns using symbols, covering basic syntax for explicitly specifying words, extended syntax such as character types (e.g., \d, \D), position anchoring, repetition control, and grouping (capturing).

The Google Tech Lead YouTuber, whom I personally admire, once uploaded a video about several essential skills every developer should know:

Among these, today’s topic is Regular Expressions, mentioned first. Number 5 seems like a bit of an outlier; I believe developers communicate more than they code, so it might not be the best strategy. Even during my undergraduate years, I often noted down “study Regular Expressions later,” but I never truly memorized them, always looking them up when needed. I recently organized them, and it turns out they’re easier to remember when categorized like grammar rules. Indeed, as the Tech Lead mentioned, Regex is widely used in development. It’s used for text searching, or more precisely, pattern matching, and has numerous use cases such as:

Regex often appears like a cipher or an alien language before you study it. This is because while common languages express semantics through words or their combinations, Regex maps semantics to individual characters, similar to a cryptographic system. However, classifying its syntax as shown below greatly aids in mastering regular expressions.

One Page Explain for Regular Expression

Fundamentally, Regular Expressions are used to search for specific words. While there’s a method to 1. explicitly specify a particular word you want to find, you can also 2. specify words as combinations of characters or numbers. Regular Expressions provide both approaches.

Basic Syntax

You can simply specify the exact word you want to search for. If you want to search for multiple words at once, you can include several words within parentheses () separated by |.

Character Sets

To specify particular characters, you can use a similar approach to specifying words, but [] allows you to find multiple characters, and within [], you can add rules for ranges like A to Z (A-Z) or exclude specific characters.

Character Types

If you want to search for numeric characters, [0-9] is good, as learned above, but you can also specify a ‘numeric’ character type. The backslash \ is used to specify character types. For example, the ‘numeric’ character type can be expressed as \d, and the ‘non-numeric’ character type can be indicated with a capital \D.

Advanced Syntax

Anchors (Positions)

Used when you want to find a specific word or character only if it appears at the very beginning or very end of a string/line.

Quantifiers (Repetition)

You can specify how many times a particular word or character should be repeated for a match.

(abc){1} = abc (exactly one occurrence)
(abc){1,3} = abc, abcabc, abcabcabc (one to three occurrences)
(abc)? = (empty string), abc (zero or one occurrence)
(abc)+ = abc, abcabc … (one or more occurrences)

Capturing = Grouping

As explained earlier, it’s used to group words for pattern searching or to save matched results when you intend to use those results.


Once learned, regular expressions are universally applicable across all programming languages and environments, offering immense utility due to the vast number of use cases in development. By organizing it this way, I should now be able to use it effectively without having to look it up every time.


Regular Expressions Explained in One Page
Author
Aaron
Posted on
Licensed Under
CC BY-NC-SA 4.0
CC BY-NC-SA 4.0
More in this category
Recent posts
The Erosion of Conversational Muscle and Communication Styles by LLM Filters
In an era where LLM tools, which filter out conversational impoliteness and deliver refined responses, have become commonplace, are we truly engaging in more thoughtful conversations? This article examines the phenomenon of conversational ability, which should be honed through countless failures in real-time communication, degenerating due to reliance on external tools. It further explores the potential societal anxieties and shifts in generational behavioral patterns that this trend may bring.
Optimal Timing and Strategy for Salary Negotiation with Senior Candidates
Salary negotiation is more than just an exchange of figures; it's a strategic dance of psychological timing. This analysis explores why engaging in a gradual negotiation process from the initial stages of recruitment, rather than waiting until after a final offer (when candidates tend to adopt a more calculative stance), proves more efficient for companies and fosters a more honest sharing of resources.
The Limits of the Rule of Law and Human Diversity
The belief that all human actions can be regulated by a single legal system may be an act of hubris. This article offers a sharp analysis of the paradox of the rule of law faced by humanity, which, having escaped the hierarchical controls of the Middle Ages, has now embraced infinite modern freedom. It further examines the deepening social coercion and the demonization of others that arise under the guise of diversity.
토스트 예시 메세지