Regular Expressions

From iMacros
Jump to: navigation, search

In computing, regular expressions, also referred to as regex or regexp, provide a concise and flexible means for matching String strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.

The following examples illustrate a few specifications that could be expressed in a regular expression:

  • The sequence of characters "car" in any context, such as "car", "cartoon", or "bicarbonate"
  • The word "car" when it appears as an isolated word
  • The word "car" when preceded by the word "blue" or "red"
  • A dollar sign immediately followed by one or more digits, and then optionally a period and exactly two more digits

As an example of the syntax, the regular expression \bex can be used to search for all instances of the string "ex" that occur after "word boundaries" (signified by the \b). In layman's terms, \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 one is a word character and the other is not a word character. Thus, 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). Regular expressions can be much more complex than these examples.

Regular expressions are used by many text editors, utilities, and programming languages - and the iMacros SEARCH command - to search text based on patterns.

More information: