sql · postgres · mysql · sqlite · local

Generate SQL regex queries

Drop a pattern in, pick flags, and get three dialect-specific snippets — PostgreSQL (~, regexp_*), MySQL 8+ (REGEXP_LIKE, REGEXP_REPLACE), and SQLite (REGEXP extension).

Regex → SQL
//g
Reminder: SQL LIKE is NOT regex — it uses % and _ wildcards.
PostgreSQL
-- PostgreSQL (POSIX regex)
-- Match in WHERE
SELECT * FROM logs WHERE message ~ '\\b\\w+@\\w+\\.\\w+\\b';

-- First match (scalar)
SELECT (regexp_match(message, '\\b\\w+@\\w+\\.\\w+\\b'))[1] AS first FROM logs;

-- All matches (returns set of arrays)
SELECT regexp_matches(message, '\\b\\w+@\\w+\\.\\w+\\b', 'g') FROM logs;

-- Replace
SELECT regexp_replace(message, '\\b\\w+@\\w+\\.\\w+\\b', '[email]', 'g') FROM logs;

-- Split
SELECT regexp_split_to_array(message, '\\b\\w+@\\w+\\.\\w+\\b') FROM logs;
SELECT regexp_split_to_table(message, '\\b\\w+@\\w+\\.\\w+\\b') FROM logs;
MySQL 8+
-- MySQL 8+ / MariaDB (ICU regex)
-- Match in WHERE (case-insensitive needs explicit flag or collation)
SELECT * FROM logs WHERE message REGEXP '\\b\\w+@\\w+\\.\\w+\\b';

-- REGEXP_LIKE with match-type flag (i, c, m, n, u)
SELECT * FROM logs WHERE REGEXP_LIKE(message, '\\b\\w+@\\w+\\.\\w+\\b', 'c');

-- First match
SELECT REGEXP_SUBSTR(message, '\\b\\w+@\\w+\\.\\w+\\b', 1, 1, 'c') AS first FROM logs;

-- Nth match (position 1, occurrence n)
SELECT REGEXP_SUBSTR(message, '\\b\\w+@\\w+\\.\\w+\\b', 1, 2, 'c') AS second FROM logs;

-- Replace all
SELECT REGEXP_REPLACE(message, '\\b\\w+@\\w+\\.\\w+\\b', '[email]', 1, 0, 'c') FROM logs;

-- Position of first match
SELECT REGEXP_INSTR(message, '\\b\\w+@\\w+\\.\\w+\\b', 1, 1, 0, 'c') FROM logs;
SQLite
-- SQLite REGEXP is an OPTIONAL extension — not built in by default.
-- Load it first, e.g. with the sqlite3 CLI:
--     .load ./regex
-- Or use a driver that registers a Python/Go/Rust regex callback.

-- Match
SELECT * FROM logs WHERE message REGEXP '\\b\\w+@\\w+\\.\\w+\\b';

-- Negated
SELECT * FROM logs WHERE message NOT REGEXP '\\b\\w+@\\w+\\.\\w+\\b';

-- SQLite has no built-in regexp_replace. Two options:
--   1) Load a regex extension that provides regexp_replace().
--   2) Pre-process the data in your application layer.

-- Caveat: SQL LIKE is NOT regex.
--   LIKE uses % (any) and _ (single char) — escape with ESCAPE.
--   SELECT * FROM logs WHERE message LIKE '%error%';
-- For regex semantics, use REGEXP (extension) or filter in app code.
Quick Start

How to use regex in SQL

SQL regex syntax differs by engine. PostgreSQL ships POSIX regex by default; MySQL 8+ ships ICU; SQLite needs an extension.

  1. 01

    Type a pattern

    Standard JS-style regex syntax. Single quotes in the pattern are auto-doubled to escape properly in SQL string literals.

    Patterns are parsed with the JavaScript RegExp constructor, so syntax errors surface immediately and engine quirks like Unicode property escapes (\p{L}) require the u flag.

    patternECMAScriptliteralregex
    input · literalpattern · regex
    WHERE x ~ '\b\w+@\w+\b'
    loaded · ECMAScripttarget · ready
  2. 02

    Tune flags

    JS i (case insensitive) maps to PostgreSQL ~* operator, MySQL 'i' match-type, SQLite collation. JS g/m have narrower SQL equivalents.

    Each flag character mirrors the ECMAScript literal: g enables iteration, i folds case, m anchors per line, s lets . match newlines, u unlocks proper Unicode, y is sticky, and d emits indices.

    flagssampleg · i · mlive
    config · optionsflags · flags
    ~* · 'i' · COLLATE
    flags applied · livelive · preview
  3. 03

    Read three snippets

    Each tab shows: WHERE clauses, capture functions, replace, split — using the dialect's native function names.

    The generator rewrites the regex for the target language — handling string-literal escaping, raw-string prefixes, and engine-specific syntax tweaks.

    codegentargetsnippetcopy
    run · outputpreview · code
    regexp_replace(col, …)
    snippet · livecode · ready
  4. 04

    Copy code

    One click copies the dialect snippet of your choice — paste into your migration or query tool.

    Copy writes via navigator.clipboard.writeText, so nothing transits the network and the output is byte-identical to what you see on screen.

    copyexportclipboardblob
    export · exportedready · saved
    Copied
    ready to shipsuccess
Pro tips

Regex patterns that don't melt down

Use named groups

(?<year>\d{4}) reads better than $1 and survives reordering. Supported in ECMAScript 2018+.

Anchor strictly

Use ^/$ with the m flag when matching whole lines. Without anchors, partial matches sneak through.

Avoid catastrophic backtracking

Nested quantifiers like (a+)+ can explode. Run patterns through ReDoS Detector first.

Escape every literal

Backslash any meta character you want literally: \.\$\^\*\+\?\(\)\[\]\{\}\|\\.

Test edge cases

Empty string, single character, unicode, the maximum length you expect — write fixtures for each.

Patterns aren&rsquo;t parsers

Don’t parse HTML, JSON, or balanced parens with regex. Use a proper parser when the grammar is recursive.

Use Cases

When to generate SQL regex queries

Skip the manual lookup when filtering text columns, building reports, or running data-cleanup migrations.

Email validation

Filter rows where email column doesn't match a basic pattern. Compiles through the JavaScript RegExp constructor — engine quirks (Unicode property escapes, sticky matching, named groups) work when their flags are on. Error messages cite the exact position of any syntax issue.

ReDoS-safe

Log mining

Extract status codes / IPs from log-line text columns with regexp_matches. Pairs with the ReDoS detector to catch catastrophic backtracking before you deploy. A pattern that handles 1k-character input fine can become a denial-of-service vector on attacker-controlled 1M-character input.

ECMA-compliant

Migration cleanup

Use regexp_replace to normalise phone numbers or addresses in bulk. Output exports as JavaScript, Python re, Java util.regex, .NET System.Text.RegularExpressions, PCRE, and POSIX — language quirks are highlighted on conversion so you don't ship a JS-only pattern to a Go service.

spec-grade

Reporting filters

Build BI report filters that match free-text fields without LIKE wildcards. Capture groups (named or numbered) round-trip cleanly into replacement strings, JSON output, or CSV extraction without re-typing. Backreferences ($1, ${name}) preserve semantics across languages.

cross-engine

Data dedup

Find rows whose key fields differ only by case or whitespace via regex. Test against edge cases — empty input, single character, max length, multibyte boundaries — to catch off-by-one and zero-length match bugs before they reach production.

test-ready

Audit queries

Spot personally identifiable data (emails, SSNs) hiding in notes columns. All matching runs client-side so secret patterns never leave the browser. Useful when the pattern itself is sensitive (PII regexes, internal data formats, security filters).

production-ready
FAQ

Frequently asked questions

PostgreSQL has the richest built-in regex (POSIX ERE + flags). MySQL 8+ uses ICU with similar features but different function names. SQLite needs a loadable extension. The tool covers all three so you can pick whichever your database is.
No. LIKE uses two wildcards — % (any sequence) and _ (single char). It's much faster than REGEXP and indexed by most databases. Use LIKE when your pattern is just a substring; reach for REGEXP only when you need true pattern matching.
Generally no — most engines fall back to a sequential scan. PostgreSQL supports trigram indexes (pg_trgm) for some regex patterns, and MySQL has FULLTEXT for word-level matching. For high-volume tables, prefilter with an indexed predicate before applying REGEXP.
Oracle uses REGEXP_LIKE / REGEXP_SUBSTR / REGEXP_REPLACE — very similar to MySQL 8. SQL Server doesn't have native regex in the standard distribution; you'd need a CLR assembly or string functions like PATINDEX.
No. The code is generated entirely in your browser.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!