A regular expression, abbreviated as RegEx or regex, is a pattern for locating a character string in a program. A regular expression can have either only regular (or simple) characters or a combination of regular and special characters. A regular expression is constructed by using normal slashes.

The purpose of using regular expressions is to identify patterns that a programmer can then act upon. Some common examples might include finding and replacing unwanted characters in a string, querying a string or group of strings to find specific information, or validating input.

Most programming languages that support Regex, regular expressions, and pattern searching have modules or libraries that support them.

To introduce a regular expression, use the import module in your program:

import re

The search method varies between programming languages. One example is using test( ) or exec( ), which stands for execute, and entering the character string between the parentheses.

Special characters in regular expressions indicate different patterns, repeats, or spaces. For example, if a program contains a set of numbers, and a regular expression is supposed to search every instance in a character string that has that set of numbers, special characters are used to indicate that pattern of numbers. The program will then know to locate each instance of that set of numbers.

To escape special characters, use backslashes around the expression. This avoids the usual function of a special character, so that they read as their literal value.


Learn more about regular expressions in Mozilla’s JavaScript Guide.

James Payne contributed to this article.

Jenna Phipps
Jenna Phipps
Jenna Phipps is a writer for, Enterprise Storage Forum, and CIO Insight. She covers data storage systems and data management, information technology security, and enterprise software solutions.

Related Articles

Built-In Function

A built-in function is a function that is already available in a programming language, application, or another tool that can be accessed by end...

AND Operator

The AND operator is a logical operator, or Boolean operator, that evaluates to TRUE if all of its operands are true and FALSE otherwise....

Visual Basic

Visual Basic is a family of programming languages developed by Microsoft. The most commonly used version of Visual Basic is Visual Basic .NET, now...

AutoIt Scripting Language

AutoIt is a popular and easy-to-learn scripting language used by developers since 1999 for quick software development. Here’s more about the AutoIt scripting language,...


ScalaHosting is a leading managed hosting provider that offers secure, scalable, and affordable...


Human resources information system (HRIS) solutions help businesses manage multiple facets of their...

Best Managed Service Providers...

In today's business world, managed services are more critical than ever. They can...