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

    mysql正则表达式

    匹配的两种方式:

    • 1.模糊匹配:like
    • 2.正则表达式

    正则表达式语法:

    语法 说明
    ^ 起始位置。如果设置了RegExp对象的Multiline属性,^也匹配' '或' '之后的位置。
    $ 结束位置。如果设置了RegExp对象的Multiline属性,$也匹配' '或' '之前的位置。
    . 匹配处 之外的任何单个字符。要匹配' '在内的任何字符,请使用'[. ]'模式
    [...] 字符集合。匹配所包含的任意一个字符。例如'[abc]'可以匹配'plain'中的a
    [^...] 负值字符集合。匹配未包含的任意字符。例如,'[^abc]'可以匹配'plain'中的'p' .这个不理解
    p1|p2|p3 匹配p1或p2或p3。例如'z|food'能匹配"z"或"food"。'(z|f)ood'则匹配"zood"或"food"。
    * 匹配前面的子表达式0次或多次。'zo'能匹配"z"以及"zoo".等价于{0,++}
    + 匹配前面的子表达式1次或多次。'zo+'能匹配"zo"以及"zoo",但不能匹配"z".+等价于{1,++}
    {n} n是一个非负整数。匹配确定的n次。例如'o{2}'不能匹配"Bob"中的"o",但能匹配"food"中的"oo"
    {n,m} m和n均为非负整数,其中n<=m。最少匹配n次且最多匹配m次
    select * from csj_tbl where csj_author REGEXP "^菜鸟";
    select * from csj_tbl where csj_author REGEXP "教程$";
    select * from csj_tbl where csj_author REGEXP "^菜鸟教程$";
    select * from csj_tbl where csj_author REGEXP "菜鸟教程.";
    select * from csj_tbl where csj_title REGEXP "学习.java";
    select * from csj_tbl where csj_title REGEXP "学习.java......";
    select * from csj_tbl where csj_title REGEXP "[abc]";
    select * from csj_tbl where csj_title REGEXP 'java|python';
    -- 增加2条记录
    insert into csj_tbl VALUES
    	(6,"zood","zoozoo",2018-11-12),
    	(7,"food","zoozoozoozoo",2018-11-12);
    select * from csj_tbl where csj_title REGEXP "(z|f)ood";
    select * from csj_tbl where csj_title REGEXP "oo*";
    select * from csj_tbl where csj_title REGEXP "o+";
    select * from csj_tbl where csj_author REGEXP "(zoo){2}";
    select * from csj_tbl where csj_author REGEXP "(zoo){3,4}";
    select * from csj_tbl where csj_author REGEXP '[^a-z0-9]';
    
    -- 查找name字段中以元音字符开头或以'ok'字符串结尾的所有数据:
    select * from person_tbl where name regexp '^[aeiou]|ok$';
    
  • 相关阅读:
    Linux 系统中 sudo 命令的 10 个技巧
    如何在 Linux 中配置基于密钥认证的 SSH
    选择 NoSQL 数据库需要考虑的 10 个问题
    10 个 Linux 中方便的 Bash 别名
    扒一扒 EventServiceProvider 源代码
    [Binary Hacking] ABI and EABI
    瀑布流 ajax 预载入 json
    PHP5+标准函数库观察者之实现
    使用汇编分析c代码的内存分布
    but no declaration can be found for element &#39;aop:aspectj-autoproxy&#39;.
  • 原文地址:https://www.cnblogs.com/csj2018/p/9950924.html
Copyright © 2011-2022 走看看