Regex Tutorial [Part – 1]

What is regex and how is it useful for anyone?

Regular Expression (also known as regex, and we will call it this only from now on) is one of the most powerful tool that can be used to manipulate text. Text manipulation that would otherwise require multiple lines of code can be done in single line using regex.

At first, regex seems to be cryptic as well as complicated but its not. Once someone understand its concept, they will appreciate its beauty, simplicity and power. It can be used by anyone. Someone does not need to be an expert developer for understanding it.  It is widely used in:

  1. Data Cleaning in Machine Learning
  2. Manipulating text in Text Editors/Excel
  3. Writing code to perform various stuffs on text

and many more places….

A brief History

Perl was one of the first programming language that included the support for regex. Later on developers from different programming languages realised the essence of regular expressions and started using regex engines in different programming languages. The most popular engine is known as PCRE (Perl Compatible Regular Expression). The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5 1. These languages include PHP, Java, Python and many others.

An example where regex is handy

NOTE: This section can be safely skipped by beginners/people with no coding background.

Example: Find the first repeating character in string abcddef (d here)

Code in some programming language

Regex Solution

Using above and functions provided by regex library of the programming language, we can find what is needed.

Summary

regex is a tool that everyone should know of. This part was just an introduction about history of regex and places where it can be used. Next part will dive more into its functionality.

  1. https://www.pcre.org/

Leave a Reply

Your email address will not be published.