Regular Expressions Introduction


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.

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.

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.

Series NavigationJavaScript String search() With a Regular Expression >>

Leave a comment

Your email address will not be published. Required fields are marked *