How JavaScript regular expressions behave
The tester runs your pattern through the browser's own RegExp engine, so it follows ECMAScript syntax. That matters when you copy patterns between languages. JavaScript supports lookahead, lookbehind in current browsers, and named groups written (?<name>...), but it has no possessive quantifiers, no atomic groups and no \A or \Z anchors. Python writes named groups as (?P<name>...).
Flags change matching in important ways. i ignores case, m makes ^ and $ match at every line break instead of only at the ends of the text, s lets the dot match newlines, and u enables full Unicode handling. The g flag finds every match rather than stopping at the first.
Worked example: the email pattern
The default pattern [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} reads as: one or more allowed characters, an at sign, one or more domain characters, a literal dot, then at least two letters. Against the sample sentence it finds two matches, support@greencodesolutions.com and sales@smarttoolpack.com. The full stop after info is not picked up because it is not followed by two letters.
It is a practical extraction pattern, not a validator. It happily accepts a..b@x..com, which no mail server would, and rejects some unusual but legal addresses such as quoted local parts. For sign-up forms, a loose check plus a confirmation email is more reliable than a stricter regex.
Greedy matching and catastrophic backtracking
Quantifiers are greedy by default. On the text <b>x</b><b>y</b>, the pattern <b>.*</b> matches the whole string, while the lazy version <b>.*?</b> stops at the first closing tag and matches only <b>x</b>.
Nested quantifiers can make the engine try an exponential number of paths when a match fails. The pattern (a+)+$ tested against a long run of the letter a followed by an exclamation mark is the textbook case: each extra character roughly doubles the work. Because this tester re-runs on every keystroke, such a pattern can freeze the browser tab. On a server the same mistake is a denial-of-service risk known as ReDoS, so avoid nesting repeated groups that can match the same characters.
SQL formatting conventions and this formatter's scope
Readable SQL usually puts each major clause on its own line with keywords in upper case, so the shape of a query is visible at a glance. SQL keywords are case-insensitive, so this is purely a convention, though quoted identifiers can be case-sensitive in databases such as PostgreSQL.
This formatter splits the query into tokens first, so string literals in single quotes, quoted identifiers ("double quotes", `backticks` or [brackets]) and comments (-- line and /* block */) are copied through exactly as written. Only the remaining SQL keywords are upper-cased. WHERE status = 'on hold' keeps 'on hold' intact.
It starts a new line for SELECT, FROM, WHERE, every JOIN form (INNER, LEFT, RIGHT, FULL OUTER, CROSS), GROUP BY, ORDER BY, HAVING, LIMIT and OFFSET, INSERT INTO with VALUES (one row per line), UPDATE with SET, and DELETE FROM. AND and OR in WHERE, HAVING and join conditions go on their own indented lines, except the AND inside BETWEEN, and subqueries in parentheses are indented. It is still a formatter, not a validator: it does not check that the query is valid for your database.
Regex & SQL Formatter: frequently asked questions
What is the difference between greedy and lazy quantifiers?
A greedy quantifier such as .* takes as much text as it can and gives back only what it must for the rest of the pattern to match. Adding a question mark, as in .*?, makes it lazy so it takes as little as possible. Lazy quantifiers are the usual fix when a match runs past the closing delimiter you wanted.
Why does ^ only match at the very start of my multi-line text?
Without the m flag, ^ and $ anchor to the start and end of the whole input. Add m to the flags field and they also match at the start and end of each line, which is what you want when testing log files or lists.
Why doesn't the dot match a line break?
By default the dot matches any character except line terminators. Add the s flag, often called dotAll, to make it match newlines too, or use a character class such as [\s\S] which works in older engines.
Does reformatting SQL change how the query runs?
Changing whitespace and keyword case does not affect the execution plan or results. Changing text inside quotes would, which is why this formatter never edits string literals, quoted identifiers or comments, and always ends a -- comment with a line break so it cannot swallow the code after it.