regex-introduccion

Introduction to RegEx

  • 3 min

🎈 We begin a course on Regular Expressions 🎉

Regular expressions (commonly known as regex) are a language for defining search patterns, used to identify and manipulate text in various computing applications.

The syntax of RegEx is hated by anyone with half a brain a significant portion of the programmer community, due to the fact that it is quite “peculiar”.

In reality, if they tried to invent something more bizarre on purpose, they wouldn’t succeed

However, RegEx are 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 I’m sure there are many very good courses, but I like to explain them my way… let’s start 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 check 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 later became 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 searching for 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 search and manipulation tasks in a (fairly) efficient manner.

It doesn’t matter if you like them or not. Nobody likes RegEx 😆. But in a lot of situations, they will save your butt.

So, let’s get to work 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 can be variations.
  • Optimization: RegEx are complex. They should be the last resort you use (when alternatives are not possible, or are even worse).
  • Use tools: Use Regex testing tools, such as Regex101 or RegEx, to experiment.