Understanding Regular Expressions
This book is 100% complete
Completed on 2018-06-17
About the Book
Exploration is not enough
Many of us default to a journey of discovery when it comes to playing around with something we don’t know well. With regular expressions, the task seems just too easy: we just have to create a short expression, right? Well, often times, this point of view is very wrong.
Trial and error often times takes more time than getting the pain handled, and getting lack of knowledge cured. Yet, most developers do this over and over again. This is because learning regular expressions seems to be too hard at first glance. Therefore, my mission is to show you that
- learning regular expressions is a lot easier than you thought,
- knowing regular expressions is fun,
- knowing regular expressions is very beneficial in many areas of your software developer career.
You can easily master regular expressions to the extent that they will do exactly what you intended them to do. This mastery comes through understanding the right theory, and a lot of practice.
Why are regular expressions important?
In today’s world, we have to deal with processing a lot of data. Accessing data is not the main problem. Filtering data is. Regular expressions provide you with one type of filter that you can use to extract data relevant to you from the big chunks of data available to you.
For instance, suppose you have an XML file containing four gigabytes of data on movies. Regular expressions make it possible to query this XML text so that you can find all movies that are filmed in Budapest in 2016 for instance.
Regular expressions are a must have for software developers.
In frontend development, we often validate input using regular expressions. Many small features are also easier with regular expressions, such as splitting strings, parsing input, matching patterns.
In backend and data science, we often search, replace, and process data using regular expressions.
In IT infrastructure, regular expressions have many use cases in Linux. VIM and EMACS also come with regex support for finding commands, as well as editing text files.
Regular expressions are everywhere. These skills come handy for you in your IT engineering career.
Why Regular Expressions are Widely Misunderstood
Regular expressions are widely misunderstood. People who taught you regular expressions either come from a theoretical point of view using formal languages and computer science, or they developed their understanding using trial and error.
According to the theoretical definition above, regexes specify a search pattern. Although this is a true statement, it is easy to misinterpret it, because we are not specifying a declarative structure. In the real world, we specify a sequence of instructions acting like a function in an imperative programming language. We use commands, loops, we pass arguments to our regex, we may pass arguments around inside our regex, we return a result, and we may even cause side-effects.
If you have dealt with at least one programming language in your life, chances are, you know almost everything to understand regular expressions. You are just not yet proficient in this weird language describing regular expressions. As soon as you familiarize yourself with this weird language, everything will fall into place.
About the Author
I am the author of two other Leanpub books:
- ES6 in Practice - The Complete Developer's Guide, and
- The Developer's Edge - How to Double Your Career Speed with Soft-Skills.
If you are still reading this page, you might wonder, when will now be a good time to master regular expressions?
During the launch period, prices are still low. Grab the book before prices are raised.
- An Introduction to Regular Expressions
Regex Syntax 101
- Formulating an Expression
- Arbitrary character class
- Basic Concatenation
- Alternative execution
- Operator precedence and parentheses
- Anchored start and end
Executing Regular Expressions
- Other PCRE-Based Regex Environments
Visualizing Regex Execution using Finite State Machines
- Regular Expressions are Finite State Machines
- Deterministic and nondeterministic Regex modeling
- Basic regex simplifications
- A successful match is cheaper than failure
- Automatically generating regex FSMs
- Match at least once
- Match At most once - optionals
- Match any number of times
- Fixed range matching
- Greedy repeat modifiers
- Lazy repeat modifiers
- Possessive repeat modifiers
Character Sets and Character Classes
- Character sets
- Character Set Ranges
- Exclusions from Character Sets
- Concatenating Advanced Language Constructs
Substring Extraction from Regular Expressions
- Defining capture groups
- Perl 6 capture groups
- Retrieval of captured substrings
- Reusing captured substrings within a regex
- Capture groups and performance
- Extensions to capture groups
Lookahead and Lookbehind
Maintaining Regular Expressions
- Extended mode
- Regex Subroutines
- Named Capture Groups
Optimizing regular expressions
- Summary of the optimization techniques
- Making character classes more specific
- Repeating character class loops
- Use possessive repeat modifiers whenever possible
- Use atomic groups
- Refactor for optimization
- Optimization techniques limit non-deterministic execution
Parsing HTML Code and URL Query Strings with Regular Expressions
- Parsing HTML tags
- Processing the Query String of a URL
This is not the end, but the beginning
- 100% Understanding Regular Expressions Guarantee
- What if I Want to Learn More?
- Upgrade Discount
- Keep in Touch
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...