MySQLdata extraction

Extract First and Last Name from Full Name in MySQL

Use MySQL string functions and REGEXP to split full name columns into first and last name parts. SQL examples for name parsing.

The Regex Pattern

Regex pattern

^([A-Za-z]+)\s+([A-Za-z]+(?:\s+[A-Za-z]+)*)$

Use this pattern with MySQL's REGEXP operator.

MySQL SQL Example

-- Split a full_name column into first_name and last_name in MySQL using SUBSTRING_INDEX and regex pattern matching
SELECT *
FROM your_table
WHERE your_column REGEXP '^([A-Za-z]+)\\s+([A-Za-z]+(?:\\s+[A-Za-z]+)*)$';

How This Works

Split a full_name column into first_name and last_name in MySQL using SUBSTRING_INDEX and regex pattern matching. 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 extraction โ€” 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