mysql第九章用正则表达式搜索

it2024-11-04  7

(1)select user_id from users where user_id REGEXP '2' order by user_id ; #搜索数据中包含2的内容 (2)select user_id from users where user_id REGEXP '.' order by user_id ; #搜索所有数据 (3)select user_id from users where user_id REGEXP '2|5' order by user_id ; #搜索2或者5的数据 (4)select first_name from users where first_name REGEXP 'ab|ad lo' order by first_name ; #搜索ad或者ab + lo的数据 (5)select first_name from users where first_name REGEXP '[a-z]lo' order by first_name ; #搜索a-z的任意字符串且lo结尾的数据

ls

(6)select user from users where user REEGEXP '\\.' order by user; #匹配特殊字符. \\是前导。\\-表示查找-,\\.表示查找。\\\匹配\ (7)select prod_name from products where prod_name REGEXP '\\([0-9] sticks?\\)' order by prod_name; #匹配到TNT (1 stick) TNT (5 sticks) (8)select prod_name from products where prod_name REGEXP '[[:digit:]]{4}' order by prod_naem; #匹配到 JetPack 1000 JetPack 2000 (9)seltct prod_name from products where prod_name REGEXP '^[0-9]\\.]' order by prod_name; #匹配到 .5 ton anvil 1 ton anvil 2 ton anvil
最新回复(0)