🎈 We start a course on Regular Expressions 🎉
Regular expressions (commonly known as regex) are a language for defining search patterns, which are used to identify and manipulate text in various computer applications.
The syntax of RegEx is hated by anyone with two fingers of sense a significant part of the programming community, due to its rather “peculiar” nature.
In reality, if they try to invent something more bizarre on purpose, they won’t succeed
However, RegEx is tremendously useful in a lot of situations (seriously, it’s not clickbait. They are very, very useful)
So since they are a very useful tool, and there are surely many great courses out there, but I like to explain them my way… let’s start with the RegEx course!
What is a regular expression?
A regular expression is simply a sequence of characters (another string) that forms a search pattern.
This pattern can be used to perform various operations on text, such as searching, matching, validating, and replacing strings.
For example, we can use a regular expression to verify if an email address has a valid format, or to find all occurrences of a keyword in a lengthy document.
Brief history of regular expressions
The history of regular expressions dates back to the 1950s, when American mathematician Stephen Cole Kleene introduced the theory of formal languages and automata. Kleene formulated concepts that would lay the groundwork for what would later be known as regular expressions.
In the 1960s, regular expressions began to appear in the context of programming, especially with the implementation of tools like grep
, which allowed for searching patterns in text files.
Since then, regular expressions have been adopted in multiple programming languages, such as Perl, Python, Java, and many more, becoming a standard in text manipulation.
Importance in modern programming
Today, regular expressions allow us to perform complex text searching and manipulation tasks in a (fairly) efficient manner.
It doesn’t matter whether you like them or not. Nobody likes RegEx 😆. But on many occasions, they will save your behind.
So let’s get to it and keep reading the rest of the course.
Tips for working with Regex
- Know your environment: The final syntax of a RegEx depends on the programming language and operating system. There may be variations.
- Optimization: RegEx can be complex. It should be the last resort you use (when alternatives are not possible or are even worse)
- Use tools: Utilize Regex testing tools, like Regex101 or RegEx, to experiment.