Regular Expression tutorial in php

SELECT with Regular Expression Syntax :

SELECT column1, column2, column3... FROM table_name WHERE column_name REGEXP pattern;


If we want to select records which contains "ra" from table name "personal" then it will fetch all records which contains "ra" combine using below shown sql query :

SELECT * FROM personal WHERE name REGEXP "ra";


If we want to select records whose name ends with "an" from table name "personal" using below shown sql query :

SELECT * FROM personal WHERE name REGEXP "an$";


If we want to select records whose name contains "ram", "prajapati" and "Jain" words at any position in whole name from table name "personal" using below shown sql query :

SELECT * FROM personal WHERE name REGEXP "ram|prajapati|Jain";


If we want to select records whose name contains any special characters like "i" and "s" from table name "personal" using below shown sql query :

In Below sql query, it will check both the characters "i" and "s" distinct as shown below :

SELECT * FROM personal WHERE name REGEXP "[is]";


If we want to select records whose name contains two specific combine characters pair like "ra" OR "ma" from table name "personal" using  below shown sql query :

SELECT * FROM personal WHERE name REGEXP "[rm]a";


If we want to select records whose name ends with any specific character like "r" OR "s" from table name "personal" using  below shown sql query :

SELECT * FROM personal WHERE name REGEXP "[rs]$";


If we want to select records whose name contains two specific combine characters pair like "ra" OR "rm" from table name "personal" using below shown sql query :

SELECT * FROM personal WHERE name REGEXP "r[am]";


If we want to select records whose name contains characters between some specific range like "a" to "j"

and also contains one other character "r" from table name "personal" using below shown sql query :

SELECT * FROM personal WHERE name REGEXP "[a-j]r";

Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions