DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Simone Gentili
Simone Gentili

Posted on

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.

Top comments (0)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: