MySQLdata validation

Validate URL Format in MySQL Using REGEXP

Check if a URL column contains valid HTTP/HTTPS URLs in MySQL using REGEXP. SQL query examples for URL validation.

The Regex Pattern

Regex pattern

^https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}([-a-zA-Z0-9()@:%_+.~#?&/=]*)$

Use this pattern with MySQL's REGEXP operator.

MySQL SQL Example

-- Filter a links or products table in MySQL to find rows where url column contains valid HTTP or HTTPS URLs
SELECT *
FROM your_table
WHERE your_column REGEXP '^https?://(www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}([-a-zA-Z0-9()@:%_+.~#?&/=]*)$';

How This Works

Filter a links or products table in MySQL to find rows where url column contains valid HTTP or HTTPS URLs. The regex pattern is used with MySQL's REGEXP operator to filter rows at the database level.

Using regex directly in SQL is efficient for use cases like data validation โ€” it avoids loading data into application memory just to filter it with a regex.

Need a custom SQL + Regex query?

Describe your specific use case in plain English. RegSQL generates the exact MySQL query with the right regex pattern for your schema.

Related SQL Patterns