/* ------------------------------------------------------------------------- */
/* Using REGEX in MySql                                                      */
/* ------------------------------------------------------------------------- */

select * from course 
where description RLIKE  'java(script)?';       --java or javascript


select  'grey'  REGEXP  'gr(a|e)y';             --gray or grey, but not griy


select case 
       when 'Advanced Sql Programming' rlike '[[:space:]]sql[[:space:]]'         
           then 'yes'  
           else 'no' 
       end as "test"; 


select  *,  'Email is valid' as "test regex"  
  from  student_email   
 where  email rlike '^[[:alnum:]]+(\.[[:alnum:]]+)*@[0-9A-z]+\.[A-z]{2,4}$';


/*TEST ANY STRING AGAINST ANY REGEX PATTERN*/
select case 
       when 'sam.sulta@hbo.com' RLIKE('^[[:alnum:]]+(\.[[:alnum:]]+)*@[0-9A-z]+\.[A-z]{2,4}$')
           then 'valid'
           else 'invalid' 
       end as "result";