MySQL常用操作(正規表現)---DAY_6

5468 ワード

-- regular expression
-- REGEXP



-- ^          

SELECT * FROM cms_user 
WHERE username REGEXP '^k';




-- $       

SELECT * FROM cms_user 
WHERE username REGEXP 'g$';




-- .         ,       

SELECT * FROM cms_user 
WHERE username REGEXP 'kin.';


SELECT * FROM cms_user 
WHERE username REGEXP 'kin.';
-- similar like __
SELECT * FROM cms_user 
WHERE username like 'k___';

-- [   ],            


SELECT * FROM cms_user 
WHERE username REGEXP '[ltog]';

SELECT * FROM cms_user 
WHERE username REGEXP '[a-k]';


-- [^    ]                

SELECT * FROM cms_user 
WHERE username REGEXP '[^ltog]';

SELECT * FROM cms_user 
WHERE username REGEXP '[^a-k]';

-- S1|S2|S3   S1,S2,S3       

SELECT * FROM cms_user 
WHERE username REGEXP 'in|ng';


-- *  0 1          

SELECT * FROM cms_user 
WHERE username REGEXP 'que*';


-- +   1          

SELECT * FROM cms_user 
WHERE username REGEXP 't+';
SELECT * FROM cms_user 
WHERE username REGEXP 'que+';



-- STRING(N)    N 


SELECT * FROM cms_user 
WHERE username REGEXP 'que{2}';




--    (M,N)    M ,  N 

SELECT * FROM cms_user 
WHERE username REGEXP 'ue{1,3}';