January 12 2013

Mysql regexp and rlike function

Tagged Under : ,

MySQL
Mysql regexp or rlike function it same as PHP preg_match() function.

It save the time write code and filter the data.

Example:
REGEXP
SELECT *
FROM table
WHERE name REGEXP '^m'; 
RLIKE
SELECT *
FROM table
WHERE name RLIKE '^m';  

Example Data
IdNameDate
1myteststring2013-01-1
2myteststring22013-01-5
3teststring2013-01-4
4examplestring2013-01-8
5examplestring2013-01-7

Query:
SELECT * FROM table WHERE name REGEXP '^m';
or
SELECT * FROM table WHERE name RLIKE '^m'; 
Output:
Id  Name            Date
--------------------------------
1   myteststring    2013-01-1
2   myteststring2   2013-01-5

Make a Comment

*

code