正则表达式用于匹配特殊的字符集合。mysql通过where子句对正则表达式提供初步的支持。
关键字regexp用来表示后面跟的东西作为正则表达式处理。
(.)是正则表达式的一个符号,表示匹配任意一个字符:
mysql> select prod_name -> from products -> where prod_name regexp '.000' -> order by prod_name;+--------------+| prod_name |+--------------+| JetPack 1000 || JetPack 2000 |+--------------+2 rows in set (0.14 sec)

|匹配符:
表示匹配其中之一
mysql> select prod_name -> from products -> where prod_name REGEXP '1000|2000' -> ORDER BY prod_name;+--------------+| prod_name |+--------------+| JetPack 1000 || JetPack 2000 |+--------------+2 rows in set (0.00 sec)
[]匹配符: 匹配几个字符之一
iWebMall 是一款高性能高扩展能力的开源 LAMP 电子商务软件,定位为大中型电子商务平台软件,服务于有建立电子商务需求的商业客户。这些商业客户不必学习任何计算机编程代码知识,只需要使用 iWebMall 软件他们就可以轻松建立一个功能强大的网上商城,实现用户注册、产品展示、在线定购、在线支付等电子商务功能;iWebMall 集成了产品发布与查询、会员注册登录、购物车、在线订单、在线支付、在
0
2 rows in set (0.00 sec)mysql> select prod_name -> from products -> where prod_name regexp '[123] Ton' -> ;+-------------+| prod_name |+-------------+| 1 ton anvil || 2 ton anvil |+-------------+2 rows in set (0.00 sec)
mysql> select prod_name from products where prod_name regexp '[1-5] Ton';+--------------+| prod_name|+--------------+| .5 ton anvil || 1 ton anvil|| 2 ton anvil|+--------------+3 rows in set (0.02 sec)
mysql> select prod_name from products where prod_name regexp '[^1-3] Ton';+--------------+| prod_name|+--------------+| .5 ton anvil |+--------------+1 row in set (0.00 sec)
匹配特殊字符,必须用//为前导。
mysql> select prod_name from products where prod_name regexp '//.' ;+--------------+| prod_name|+--------------+| .5 ton anvil |+--------------+1 row in set (0.00 sec)
匹配字符类:

mysql> select prod_name from products where prod_name REGEXP '//([0-9] sticks?//)' order by prod_name;+----------------+| prod_name|+----------------+| TNT (1 stick)|| TNT (5 sticks) |+----------------+2 rows in set (0.05 sec)mysql> select prod_name from products where prod_name REGEXP '[[:digit:]]{4}' order by prod_name;+--------------+| prod_name|+--------------+| JetPack 1000 || JetPack 2000 |+--------------+2 rows in set (0.00 sec)定位符用法:
mysql> select prod_name -> from products -> where prod_name REGEXP '^[0-9//.]' -> order by prod_name;+--------------+| prod_name |+--------------+| .5 ton anvil || 1 ton anvil|| 2 ton anvil|+--------------+3 rows in set (0.00 sec)
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号