What is a POSIX BRE compliant regex?

sensorario profile image Simone Gentili ・1 min read

POSIX is the acronym for “Portable Operating System Interface for uniX”. It is a collection of standards. This collection define some of the functionality that a (UNIX) operating system should support.

BRE stands for Basic Regular Expressions or BRE, and standardize a flavor similar to the one used by the traditional UNIX grep command.

A BRE supports POSIX bracket expressions, which are similar to character classes in other regex flavors, with a few special features.

In regex a series of shorthand character classes are available. \d is short for [0-9]. In POSIX BRE shorthands are not supported.

The BRE a{1,2} matches a{1,2} literally, while a{1,2} matches a or aa.

Some implementations support \? and + as an alternative syntax to {0,1} and {1,}, but \? and + are not part of the POSIX standard.

Tokens can be grouped with ( and ).

Backreferences are the usual \1 through \9. Only up to 9 groups are permitted. E.g. (ab)\1 matches abab, while (ab)\1 is invalid since there’s no capturing group corresponding to the backreference \1. Use \1 to match \1 literally.


markdown guide