Mysql – Regex Operator

In Mysql if we want to run a query that has condition like record should start with ‘D’ or ‘E’.
Normally we use Like Operator.

select * from tablename where name like 'D%' OR name like 'E%'

But using REGEX in MySql we can get same result without using OR in query

select * from table where title REGEXP '^(D|E)';

In the query described above we use REGEXP and in ‘ we use ^(Caret sign – Regular Expression’s reserved character to enforce a character should appear in start of a word).


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.