PG
PRO

SQL Regex Tester

Test PostgreSQL POSIX and SIMILAR TO patterns — highlights capture groups and generates all equivalent SQL functions.

How it works: Type a pattern below and it highlights matches in real time. The PostgreSQL Equivalent panel at the bottom generates the exact SQL you need — copy and paste into your query. Use Examples to load common patterns instantly, or open the Usage Guide for a full walkthrough of operators, use cases, and indexing tips.
/\b\w{4}\b/gi
Pattern breakdown — hover each token to understand your regex
\bword boundary·
\wword char [a-zA-Z0-9_]·
{4}exactly 4·
\bword boundary
Index suitability — can PostgreSQL use an index for this pattern?
ℹ️Info:Add a pg_trgm GIN index: CREATE INDEX ON table USING gin(col gin_trgm_ops)
The quick brown fox jumps **** the **** dog
Result2 matches
The quick brown fox jumps over the lazy dog
Matches
#1"over"@ 26
#2"lazy"@ 35
PostgreSQL Equivalent
-- Test if matches (case-sensitive)
SELECT 'The quick brown fox jumps over the lazy dog' ~ '\b\w{4}\b';

-- Case-insensitive match
SELECT 'The quick brown fox jumps over the lazy dog' ~* '\b\w{4}\b';

-- regexp_like (boolean, cleaner)
SELECT regexp_like('The quick brown fox jumps over the lazy dog', '\b\w{4}\b', 'i');

-- Count occurrences
SELECT regexp_count('The quick brown fox jumps over the lazy dog', '\b\w{4}\b', 1, 'i');

-- Extract first match
SELECT regexp_match('The quick brown fox jumps over the lazy dog', '\b\w{4}\b', 'i');

-- Extract all matches
SELECT regexp_matches('The quick brown fox jumps over the lazy dog', '\b\w{4}\b', 'gi');

-- Replace
SELECT regexp_replace('The quick brown fox jumps over the lazy dog', '\b\w{4}\b', '****', 'gi');

-- Extract substring
SELECT regexp_substr('The quick brown fox jumps over the lazy dog', '\b\w{4}\b', 1, 1, 'i');

-- Split to array
SELECT regexp_split_to_array('The quick brown fox jumps over the lazy dog', '\b\w{4}\b', 'i');

PostgreSQL note: PostgreSQL uses POSIX extended regular expressions (ERE). The ~ and regexp_* functions use POSIX patterns. SIMILAR TO uses SQL-standard syntax with different metacharacters. JavaScript regex is broadly compatible but has minor differences in some escape sequences.