This is an old version, saved 5 Dec 2026, 05:27 by TechWritereditor. See the current version.
Regular expression
Regular expressions are patterns used to match combinations of characters in strings of text.[1] They let a user describe not just a fixed word but a whole family of strings – for example, "any three digits" – and then find, test or replace every match.[1]
History
Regular expressions are closely linked to the theory of finite automata. In 1951 the mathematician Stephen Kleene wrote a RAND Corporation research memorandum, Representation of Events in Nerve Nets and Finite Automata, examining the kinds of events a finite automaton can respond to.[2]
Ken Thompson brought regular expressions into practical computing. According to Dennis Ritchie, Thompson's version of the QED text editor, written for the CTSS time-sharing system, differed from earlier versions mainly by introducing regular expressions for specifying the strings to search for; before this, editors could search only for literal text.[3] Thompson described his method in the paper "Regular expression search algorithm" in Communications of the ACM in 1968.[3] His technique compiled each expression on the fly into machine code that simulated a nondeterministic finite automaton.[3] The paper explains a compiler that takes a regular expression as its source language and produces an IBM 7094 program that signals each time a piece of text matches.[4]
When Thompson wrote the ed editor for Unix, he radically simplified the notation, and later Unix tools such as grep continued Bell Labs' work on fast regular-expression matching.[3]
How it works
A regular expression mixes ordinary characters with special symbols. In the pattern ab*c, the * means "zero or more of the preceding item", so it matches "ac", "abc", "abbbbc" and so on.[1] The sequence \d{3} means three numeric characters.[1]
In JavaScript, a regular expression can be written between slashes, as in /ab+c/, or built with the RegExp constructor, which is useful when part of the pattern comes from user input.[1] Methods such as test(), match(), replace() and split() let programs check for a match, collect matches, substitute text or break a string into pieces.[1]
See also
References
- ^ Regular expressions – JavaScript guide. MDN Web Docs (Mozilla). developer.mozilla.org
- ^ Representation of Events in Nerve Nets and Finite Automata. RAND Corporation. 1951-12-15. rand.org
- ^ An incomplete history of the QED Text Editor. Nokia Bell Labs. nokia.com
- ^ Programming Techniques: Regular expression search algorithm. Communications of the ACM. cacm.acm.org