Regular Expression

In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize) strings of text, such as particular characters, words, or patterns of characters. Common abbreviations for "regular expression" include regex and regexp.

The concept of regular expressions was first popularized by utilities provided by Unix distributions, in particular the editor ed and the filter grep. A regular expression is written in a formal language that can be interpreted by a regular expression processor, which is a program that either serves as a parser generator or examines text and identifies parts that match the provided specification. Historically, the concept of regular expressions is associated with Kleene's formalism of regular sets, introduced in the 1950s.

The following are examples of specifications which can be expressed as a regular expression:

  • The sequence of characters "car" appearing consecutively, such as in "car", "cartoon", or "bicarbonate"
  • The word "car" when it appears as an isolated word (and delimited from other words, typically through whitespace characters)
  • The word "car" when preceded by the word "motor" (and separated by a named delimiter, or multiple.)

Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. Some of these languages, including Perl, Ruby, AWK, and Tcl, integrate regular expressions into the syntax of the core language itself. Other programming languages like .NET languages, Java, and Python instead provide regular expressions through standard libraries. For yet other languages, such as Object Pascal (Delphi) and C and C++, non-core libraries are available (however, version C++11 provides regular expressions in its Standard Libraries).

As an example of the syntax, the regular expression \bex can be used to search for all instances of the string "ex" occurring after "word boundaries". Thus \bex will find the matching string "ex" in two possible locations, (1) at the beginning of words, and (2) between two characters in a string, where the first is not a word character and the second is a word character. For instance, in the string "Texts for experts", \bex matches the "ex" in "experts" but not in "Texts" (because the "ex" occurs inside a word and not immediately after a word boundary).

Many modern computing systems provide wildcard characters in matching filenames from a file system. This is a core capability of many command-line shells and is also known as globbing. Wildcards differ from regular expressions in generally expressing only limited forms of patterns.

Read more about Regular Expression:  History, Basic Concepts, Formal Language Theory, Syntax, Patterns For Non-regular Languages, Fuzzy Regular Expressions, Implementations and Running Times, Unicode, Uses, Examples

Famous quotes containing the words regular and/or expression:

    A regular council was held with the Indians, who had come in on their ponies, and speeches were made on both sides through an interpreter, quite in the described mode,—the Indians, as usual, having the advantage in point of truth and earnestness, and therefore of eloquence. The most prominent chief was named Little Crow. They were quite dissatisfied with the white man’s treatment of them, and probably have reason to be so.
    Henry David Thoreau (1817–1862)

    They are not callow like the young of most birds, but more perfectly developed and precocious even than chickens. The remarkably adult yet innocent expression of their open and serene eyes is very memorable. All intelligence seems reflected in them. They suggest not merely the purity of infancy, but a wisdom clarified by experience. Such an eye was not born when the bird was, but is coeval with the sky it reflects. The woods do not yield another such a gem.
    Henry David Thoreau (1817–1862)