Mark As Completed Discussion

What are Regular Expressions?

Regular expressions, also known by the shorthand regex, are a special sequence of characters that define a certain pattern. This sequence is then used to match text according to the defined pattern.

You might be wondering-- why do we need another method to perform text matching, when we can already do it using:

  1. the equal operator (==)
  2. by indexing, or
  3. via string methods in any programming language?

It's because regular expressions are a more powerful (and much shorter!) method of performing the string matching operation, one where you can match strings even with custom-defined patterns, a functionality that you might not be able to perform using other methods.

Regular expressions can ease our day to day programming as well. Suppose you receive the data of personal information of people in your university, and you want to extract all the emails from it. If this is done manually, it would surely take quite some time. But don't worry! Regular expressions can make it easy, by solving this problem in a single line.

What are Regular Expressions?