How to Test Regular Expressions and Format Raw SQL Queries in One Tool
Learn how to check a JavaScript regex against sample text with live match listing, then switch tabs to break a one-line SQL query into readable clauses.
Regex & SQL Formatter
Introduction
Patterns and queries are both easy to get subtly wrong, and both are faster to fix with instant feedback. The Regex Tester tab runs a JavaScript RegExp against sample text and lists every match, while the SQL Formatter tab splits a query onto clause-based lines with uppercased keywords, leaving string literals, quoted identifiers and comments untouched. Both run in the browser.
Step-by-Step Instructions
- Click the Regex Pattern Tester tab and enter the pattern in the Regex Pattern field without surrounding slashes.
- Set the Flags field (keep g for all matches; add i for case-insensitive or m for multiline).
- Paste sample input into Test Text String and read the Matched Groups panel, which lists each match with its index.
- Switch to the SQL Query Formatter tab and paste the query into Raw Unformatted SQL.
- Read the Formatted SQL Output panel and click Copy SQL to copy the result.
Key Use Cases
- Form validation: Confirm an email or phone pattern matches the expected inputs and nothing else.
- Log parsing: Extract ids or timestamps from a block of log lines before writing a script.
- Code review: Reformat a long ORM-generated query so joins and filters are visible at a glance.
Frequently Asked Questions
Why does the tester show an error when the g flag is removed?
Matches are collected with String.prototype.matchAll, which requires a global regular expression. Without g the browser throws, and the message appears in the Regex Syntax Error box. Keep g in the Flags field and combine it with i, m, s or u as needed.
Does the match list show capture groups?
No. The Matched Groups panel lists the full text of each match in order, not the individual capturing groups within it. To inspect a sub-part, adjust the pattern so the part you want is the whole match.
How does the SQL formatter decide where to break lines?
It tokenizes the query first, so text inside 'single quotes', quoted identifiers and -- or /* */ comments is never changed. Each clause starts a new line: SELECT, FROM, WHERE, every JOIN form including LEFT, RIGHT, INNER and FULL OUTER JOIN, GROUP BY, ORDER BY, HAVING, LIMIT, INSERT INTO with VALUES, UPDATE with SET, and DELETE FROM. AND and OR conditions get their own indented lines, and subqueries are indented. For example, select * from t where status = 'on hold' and x = 1 or y = 2 keeps 'on hold' intact and puts the AND and OR conditions on separate lines. It does not validate syntax.