Regular Expressions in Python

Author

Kurian Benoy

Published

July 21, 2021

Regex image

In Python, regular expressions is a very powerful gun. Let’s look what these gun can do:. I first learned about regular expressions in Theory Of automate(TOC).

According to wikipedia regext is defined as follows.

A regular expression (shortened as regex or regexp) is a sequence of characters that specifies a search pattern. Usually such patterns are used by string-searching algorithms for “find” or “find and replace” operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory.

The formal definition of Regular expression as mentioned in Theory of Computer text books is as follows:

Regular expressions consist of constants, which denote sets of strings, and operator symbols, which denote operations over these sets. The following definition is standard, and found as such in most textbooks on formal language theory.[20][21] Given a finite alphabet Σ, the following constants are defined as regular expressions:

(empty set) ∅ denoting the set ∅. (empty string) ε denoting the set containing only the “empty” string, which has no characters at all. (literal character) a in Σ denoting the set containing only the character a.

Since we are learning regex in Python. Let me share two handy resorurces to learn regex:

  1. It’s very useful to search and find things quickly. It consists of various methods like:

https://docs.python.org/3/howto/regex.html https://www.infoworld.com/article/3306798/regex-tutorial-matching-sets-of-characters.html https://brilliant.org/practice/regular-expressions/ https://elisonsherton.github.io/fastbook/deep%20learning/2021/07/19/fastbook-week6-session-summary.html

Today regarding regex, learned about techniques like re.match, re.matchall()

*, /,/d etc. Practising problems can only make you perfect.

Regular Expressions is a very useful feature to search and find things quickly. The various methods of regular experessions consists of: