regular expression

From IndieWeb
Jump to: navigation, search


A regular expression is a sequence of characters used to match, extract, and/or replace patterns in text.

Flavours

There are many different implementations of regular expressions. This means a regular expression that works on one platform may not be supported on an other.

PCRE

PCRE, or Perl Compatible Regular Expressions, is an implementation that started 1997 with the aim of bringing Perlโ€™s regular expressions to other platforms.

Because of its widespread use, it in turn has introduced new syntax. Some of these have then been brought back into the original Perl implementation.

Differences between PCRE and Perl are documented on Wikipedia and by The PHP Group.

PCRE2 was released at the start of 2015. PHP has switched from PCRE to PCRE2 in PHP 7.3, which was released in December 2018.

POSIX

The POSIX standard defines regular expressions for use by operating systems in an interoperable manner. This flavour is implemented by CLI tools such as grep.

PHP used to support POSIX Extended regular expressions through the ereg set of functions. This was deprecated by PHP 5.3 in favour of the PCRE implementation.

The PHP Group documents some notable differences between POXIS and PCRE. These should help getting started on converting between the two formats, though isnโ€™t an extensive comparison.

See Also