Regular Expressions Introduction


This entry is part 1 of 5 in the series Regular Expressions

A regular expression is a way to express a pattern to match strings of text. The expression itself consists of terms and operators that allow us to define these patterns. “RegExp” stands for regular expression.

You can test your regular expressions online at www.regexpal.com.

This discussion will be in the context of using regular expressions with JavaScript.

The search pattern can be used for text search and text replace operations. A regular expression can be a single character, or a more complicated pattern. Regular expressions can be used to perform all types of text search and text replace operations.

The syntax and an example follows:

/pattern/modifiers;
var patt = /w3schools/i;

the i above modifies the search to be case insensitive.

YouTube Resources

There are several YouTube videos on Regular Expressions. Here are just a few I’ve found.

Website Tutorial

Here is a tutorial on Regex called Regular-Expressions.info.

JavaScript String Methods

JavaScript has a small set of standard methods that are available on the standard types. Methods are available for: array, function, number, object, regexp and string.

In JavaScript, regular expressions are often used with the two string methods: search() and replace(). The search() method uses an expression to search for a match, and returns the position of the match. The replace() method returns a modified string where the pattern is replaced.

The next post JavaScript String search() With a Regular Expression uses an example from the website w3Schools to demonstrate the search() method.

Flavours of RegEx

There is no official standard that defines exactly which text patterns are regular expressions and which aren’t. Every professional has a different idea of exactly what a regular expression should be. So we have a whole palette of regular expression flavors. Fortunately, all modern regular expression flavours can be traced back to the Perl programming language.

The Microsoft .NET Framework provides a full-featured Perl-style regex flavor through the System.Text.RegularExpressions package. The Regex class got a few new methods in .NET 4.0, but the regex syntax is unchanged. Any .NET programming language, including C#, VB.NET, Delphi for .NET, and even COBOL.NET, has full access to the .NET regex flavor.

Series NavigationRegular Expressions Exact Match >>