18 Apr 2014
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).