zoukankan      html  css  js  c++  java
  • mysql 正则表达式

    mysql> select * from test;
    +----+----------+-------+-----------+
    | id | name     | score | subject   |
    +----+----------+-------+-----------+
    |  1 | xiaoming |    89 | shuxue    |
    |  2 | xiaohong |    89 | shuxue    |
    |  3 | xiaohong |    80 | english   |
    |  4 | xiaohong |    80 | physics   |
    |  5 | xiaohong |    80 | astronaut |
    |  6 | xiaoming |    80 | physics   |
    |  7 | xiaoming |    80 | astronaut |
    |  8 | xiaoming |    80 | english   |
    |  9 | xiaobai  |    80 | astronaut |
    | 10 | xiaobai  |    80 | english   |
    | 11 | xiaobai  |    80 | physics   |
    | 12 | xiaobai  |    80 | shuxue    |
    | 13 | xiaohei  |    80 | astronaut |
    | 14 | xiaohei  |    80 | shuxue    |
    | 15 | xiaohei  |    80 | physics   |
    | 16 | xiaohei  |    80 | english   |
    +----+----------+-------+-----------+
    16 rows in set (0.00 sec)
    
    
    
    mysql> select * from test where subject regexp "sh";
    +----+----------+-------+---------+
    | id | name     | score | subject |
    +----+----------+-------+---------+
    |  1 | xiaoming |    89 | shuxue  |
    |  2 | xiaohong |    89 | shuxue  |
    |  3 | xiaohong |    80 | english |
    |  8 | xiaoming |    80 | english |
    | 10 | xiaobai  |    80 | english |
    | 12 | xiaobai  |    80 | shuxue  |
    | 14 | xiaohei  |    80 | shuxue  |
    | 16 | xiaohei  |    80 | english |
    +----+----------+-------+---------+
    8 rows in set (0.00 sec)
    
    
    
    mysql> select * from test where subject regexp "^sh";
    +----+----------+-------+---------+
    | id | name     | score | subject |
    +----+----------+-------+---------+
    |  1 | xiaoming |    89 | shuxue  |
    |  2 | xiaohong |    89 | shuxue  |
    | 12 | xiaobai  |    80 | shuxue  |
    | 14 | xiaohei  |    80 | shuxue  |
    +----+----------+-------+---------+
    4 rows in set (0.00 sec)
    
    
    mysql> select * from test where subject regexp "^[sp]h";
    +----+----------+-------+---------+
    | id | name     | score | subject |
    +----+----------+-------+---------+
    |  1 | xiaoming |    89 | shuxue  |
    |  2 | xiaohong |    89 | shuxue  |
    |  4 | xiaohong |    80 | physics |
    |  6 | xiaoming |    80 | physics |
    | 11 | xiaobai  |    80 | physics |
    | 12 | xiaobai  |    80 | shuxue  |
    | 14 | xiaohei  |    80 | shuxue  |
    | 15 | xiaohei  |    80 | physics |
    +----+----------+-------+---------+
    8 rows in set (0.00 sec)
    
    
    
    mysql> select * from test where subject regexp "^s|ph";
    +----+----------+-------+---------+
    | id | name     | score | subject |
    +----+----------+-------+---------+
    |  1 | xiaoming |    89 | shuxue  |
    |  2 | xiaohong |    89 | shuxue  |
    |  4 | xiaohong |    80 | physics |
    |  6 | xiaoming |    80 | physics |
    | 11 | xiaobai  |    80 | physics |
    | 12 | xiaobai  |    80 | shuxue  |
    | 14 | xiaohei  |    80 | shuxue  |
    | 15 | xiaohei  |    80 | physics |
    +----+----------+-------+---------+
    8 rows in set (0.00 sec)
    
    
    
    mysql> select * from test where name regexp "xiaoming|xiaohei";
    +----+----------+-------+-----------+
    | id | name     | score | subject   |
    +----+----------+-------+-----------+
    |  1 | xiaoming |    89 | shuxue    |
    |  6 | xiaoming |    80 | physics   |
    |  7 | xiaoming |    80 | astronaut |
    |  8 | xiaoming |    80 | english   |
    | 13 | xiaohei  |    80 | astronaut |
    | 14 | xiaohei  |    80 | shuxue    |
    | 15 | xiaohei  |    80 | physics   |
    | 16 | xiaohei  |    80 | english   |
    +----+----------+-------+-----------+
    8 rows in set (0.00 sec)
    mysql> select * from test;
    +----+----------+-------+-----------+
    | id | name     | score | subject   |
    +----+----------+-------+-----------+
    |  1 | xiaoming |    89 | shuxue    |
    |  2 | xiaohong |    89 | shuxue    |
    |  3 | xiaohong |    80 | english   |
    |  4 | xiaohong |    80 | physics   |
    |  5 | xiaohong |    80 | astronaut |
    |  6 | xiaoming |    80 | physics   |
    |  7 | xiaoming |    80 | astronaut |
    |  8 | xiaoming |    80 | english   |
    |  9 | xiaobai  |    80 | astronaut |
    | 10 | xiaobai  |    80 | english   |
    | 11 | xiaobai  |    80 | physics   |
    | 12 | xiaobai  |    80 | shuxue    |
    | 13 | xiaohei  |    80 | astronaut |
    | 14 | xiaohei  |    80 | shuxue    |
    | 15 | xiaohei  |    80 | physics   |
    | 16 | xiaohei  |    80 | english   |
    +----+----------+-------+-----------+
    16 rows in set (0.00 sec)
    
    
    mysql> update test set name="1.2xiaobai" where id=10;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    
    mysql> select * from test;
    +----+------------+-------+-----------+
    | id | name       | score | subject   |
    +----+------------+-------+-----------+
    |  1 | xiaoming   |    89 | shuxue    |
    |  2 | xiaohong   |    89 | shuxue    |
    |  3 | xiaohong   |    80 | english   |
    |  4 | xiaohong   |    80 | physics   |
    |  5 | xiaohong   |    80 | astronaut |
    |  6 | xiaoming   |    80 | physics   |
    |  7 | xiaoming   |    80 | astronaut |
    |  8 | xiaoming   |    80 | english   |
    |  9 | xiaobai    |    80 | astronaut |
    | 10 | 1.2xiaobai |    80 | english   |
    | 11 | xiaobai    |    80 | physics   |
    | 12 | xiaobai    |    80 | shuxue    |
    | 13 | xiaohei    |    80 | astronaut |
    | 14 | xiaohei    |    80 | shuxue    |
    | 15 | xiaohei    |    80 | physics   |
    | 16 | xiaohei    |    80 | english   |
    +----+------------+-------+-----------+
    16 rows in set (0.00 sec)
    
     
    mysql> select * from test where name regexp "\.";
    +----+------------+-------+---------+
    | id | name       | score | subject |
    +----+------------+-------+---------+
    | 10 | 1.2xiaobai |    80 | english |
    +----+------------+-------+---------+
    1 row in set (0.00 sec)
    
    
    mysql> update test set name="2.2xiaobai" where id=11;
    Query OK, 1 row affected (0.01 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    
    mysql> select * from test where name regexp "[12]";
    +----+------------+-------+---------+
    | id | name       | score | subject |
    +----+------------+-------+---------+
    | 10 | 1.2xiaobai |    80 | english |
    | 11 | 2.2xiaobai |    80 | physics |
    +----+------------+-------+---------+
    2 rows in set (0.00 sec)
    
    
    mysql> update test set name="3xiaobai" where id=12;
    Query OK, 1 row affected (0.01 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    
    mysql> select * from test where name regexp "[12]";
    +----+------------+-------+---------+
    | id | name       | score | subject |
    +----+------------+-------+---------+
    | 10 | 1.2xiaobai |    80 | english |
    | 11 | 2.2xiaobai |    80 | physics |
    +----+------------+-------+---------+
    2 rows in set (0.00 sec)
    
    
    mysql> select * from test where name regexp "[12]\.";
    +----+------------+-------+---------+
    | id | name       | score | subject |
    +----+------------+-------+---------+
    | 10 | 1.2xiaobai |    80 | english |
    | 11 | 2.2xiaobai |    80 | physics |
    +----+------------+-------+---------+
    2 rows in set (0.00 sec)
    
    
    mysql> select * from test where name regexp "[123]\.";
    +----+------------+-------+---------+
    | id | name       | score | subject |
    +----+------------+-------+---------+
    | 10 | 1.2xiaobai |    80 | english |
    | 11 | 2.2xiaobai |    80 | physics |
    +----+------------+-------+---------+
    2 rows in set (0.00 sec)
    
    
    mysql> select * from test where name regexp "[123]";
    +----+------------+-------+---------+
    | id | name       | score | subject |
    +----+------------+-------+---------+
    | 10 | 1.2xiaobai |    80 | english |
    | 11 | 2.2xiaobai |    80 | physics |
    | 12 | 3xiaobai   |    80 | shuxue  |
    +----+------------+-------+---------+
    3 rows in set (0.00 sec)

  • 相关阅读:
    [ACM_模拟] ZJUT 1155 爱乐大街的门牌号 (规律 长为n的含k个逆序数的最小字典序)
    [ACM_搜索] ZOJ 1103 || POJ 2415 Hike on a Graph (带条件移动3盘子到同一位置的最少步数 广搜)
    [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)
    [ACM_搜索] POJ 1096 Space Station Shielding (搜索 + 洪泛算法Flood_Fill)
    [JAVA] java_实例 获得系统字体
    [JAVA] java仿windows 字体设置选项卡
    [JAVA] 一个可以编辑、编译、运行Java简单文件的记事本java实现
    [ACM_模拟] POJ 1094 Sorting It All Out (拓扑排序+Floyd算法 判断关系是否矛盾或统一)
    JS的数组相关知识
    JS的join方法
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11306557.html
Copyright © 2011-2022 走看看