Regular Expressions/POSIX Basic Regular Expressions

The POSIX Basic Regular Expression (BRE) syntax provided extensions to achieve consistency between utility programs such as grep, sed and awk. These extensions are not supported by some traditional implementations of Unix tools.

History
Traditional Unix regular expression syntax followed common conventions that often differed from tool to tool. The POSIX Basic Regular Expressions syntax was developed by the IEEE, together with an extended variant called Extended Regular Expression syntax. These standards were designed mostly to provide backward compatibility with the traditional ../Simple Regular Expressions/ syntax, providing a common standard which has since been adopted as the default syntax of many Unix regular expression tools.

Syntax
In POSIX Basic Regular Expression syntax, most characters are treated as literals — they match only themselves (e.g.,  matches "a"). The exceptions, listed below, are called metacharacters or metasequences.

Examples:
 * matches any three-character string ending with "at", including "hat", "cat", and "bat".
 * matches "hat" and "cat".
 * matches all strings matched by  except "bat".
 * matches "hat" and "cat", but only at the beginning of the string or line.
 * matches "hat" and "cat", but only at the end of the string or line.
 * matches any single character surrounded by "[" and "]" since the brackets are escaped, for example: "[a]" and "[b]".

Character classes
The POSIX standard defines some classes or categories of characters as shown below. These classes are used within brackets.

For example,
 * matches "a0b", "a1b", ..., "a9b".
 * is an error: character classes must be in brackets
 * matches any digit, "a", "b", and "c".
 * is the same as above
 * matches any character except lowercase letters, A, B, and Z.

Collating symbols
Collating symbols, like character classes, are used in brackets and have the form. Here  is a digraph. Collating systems are defined by the locale.

Equivalence classes
Equivalence classes, like character classes and collating symbols, are used in brackets and have the form. They stand for any character which is equivalent to the given. According to the standard, "For example, if 'a', 'à', and 'â' belong to the same equivalence class, then '[[=a=]b]', '[[=à=]b]', and '[[=â=]b]' are each equivalent to '[aàâb]'.|undefined"

Equivalence classes, like collating symbols, are defined by the locale.

Use in Tools
Tools and languages that utilize this regular expression syntax include:


 * TextPad
 * Zabbix