DEV Community

Simone Gentili
Simone Gentili

Posted on

3

What is a POSIX BRE compliant regex?

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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs