Skip menu

Zoรซ Blade's notebook

Regular expressions

๐‘ฎ๐‘ง๐‘œ๐‘˜๐‘ฉ๐‘ค๐‘ผ ๐‘ฆ๐‘’๐‘•๐‘๐‘ฎ๐‘ง๐‘–๐‘ฉ๐‘ฏ๐‘Ÿ

Regular expressions, or regex for short, are a means of finding, replacing, validating, and semantically identifying phrases within plain text.

They're a core part of the Unix toolset, implemented in standard Unix utilities such as ed, sed, grep, ex, and vi; programming languages such as awk and Perl; and server software modules such as Apache's mod_rewrite and Nginx's ngx_http_rewrite_module.

As is often the case when threatened with the possibility of a single useful standard, different engineers blessed us with competing variations, including BREs, EREs, and PCREs. It's therefore important to check which variation you're using before you get too far writing an especially complex regular expression.

Contrast with the much simpler wildcards, as used at the command line to refer to multiple files at once.

See also

Further reading

Deep dives

Pattern matching syntaxes: Regular expressions