Regular expression (Definition)

A means of matching patterns of text in string values.

Regular expressions are a way of describing a pattern match that can be used to select a group of characters from an input string. This usually then leads on to replacing them with some other set of characters. It is analogous to the find and replace capability in a word processor.

JavaScript version 1.2 introduced regular expression support by way of a specialized object, a utility that UNIX developers have long known about and used. It has migrated into many desktop applications now and has become a somewhat portable way of matching text strings with one another and performing edits on them. The regular expression syntax adopted by JavaScript version 1.2 emulates that which is commonly used in Perl interpreters, specifically the syntax that is supported is generally called Perl version 4. In JavaScript version 1.3, the regular expression syntax was expanded to support Perl version 5 syntax.

Regular expressions are managed by creating a RegExp object with the RegExp() constructor. RegExp objects support a literal syntax and can be created on the fly without needing a constructor call which makes them extremely convenient to deploy.

The ECMAScript standard ratifies regular expressions in the third edition. They were not present in the second edition.


See also:Fundamental data type, JellyScript, RegExp pattern, RegExp pattern - character literal, RegExp(), RegExp.exec(), String.match(), String.replace(),, String.split()


O'Reilly JavaScript Definitive Guide - page - 49