The Absolute Basics
A regular expression (regex) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings.
Literal Characters
The most basic regular expression consists of a single literal character, such as a. It matches the first occurrence of that character in the string. If the string is "Jack is a boy", it matches the "a" after the "J".
Interactive Example
Click the button below to see how this simple pattern looks in our visualizer, along with its Abstract Syntax Tree (AST).
Open in VisualizerThe Global Flag
By default, a regex will stop searching after it finds the very first match. If you want it to find all matches in the text, you need to append the global flag g to the end of your expression.
Knowledge Check
In JavaScript, the syntax looks like this: /pattern/g. The slashes denote the start and end of the expression, and the g is the flag.